SlideShare ist ein Scribd-Unternehmen logo
1 von 15
Downloaden Sie, um offline zu lesen
Boulos Dib
Independent Consultant
       Napeague Inc.
           February 10, 2011
   A Silverlight infrastructure to connect business
    model with UI Controls.

   Data Binding is not about data access, data
    controls, data layer, data models or databases.

   Not unique to Silverlight. Other technologies
    implement data binding: ASP.NET, Adobe Flex, WPF

   The System.Windows.Data.Binding class is used to
    make the connection .
   Binding connection is defined by 3 elements:
    ◦ Source of the data (CLR Object)
    ◦ Binding Mode (Direction of flow)
    ◦ Target for the data (Dependency Property)

   Value Converters enhance or override binding; an
    extensibility point.
   TextBox in XAML
   <TextBox x:Name=“myTextBox” />


   Binding via code-behind
   DateTime currentTime = DateTime.Now;
   Binding binding = new Binding(“TimeOfDay”);
   binding.Source = currentTime;
   binding.Mode = BindingMode.OneWay;
   myTextBox.SetBinding(TextBox.TextProperty, binding);


   Unbind a data source (code only)
   myTextBox.Text = “Binding Removed”;
   TextBox in XAML (Binding Expression)
    <TextBox x:Name=“myTextBox”
        Text=“{Binding TimeOfDay, Mode=OneWay}” />
    ---or---
    <TextBox x:Name=“myTextBox”
        Text=“{Binding Path=TimeOfDay, Mode=OneWay}” />

   Alternate - Object Element Syntax
<TextBox x:Name=“myTextBox”>
  <TextBox.Text>
      <Binding Path=“TimeOfDay” Mode=“OneWay” />
  </TextBox.Text>
</TextBox>
   ElementName
   Source property
   RelativeSource property
    ◦ Self
    ◦ TemplateParent


   Or
   If not set, the source is implicitly set via
    inherited DataContext.
   Simple property
    ◦ {Binding ElementName=LayoutRoot, Path=myProperty}
   Nested Property
    ◦ {Binding ElementName=LayoutRoot, Path=Background.Color}
   Collection – set the Path to current item
    ◦ {Binding Path=myCollection.CurrentItem.Property}
   Item in a collection - use indexer
    ◦ {Binding Path=MyCollection[0]}
    ◦ Or
    ◦ {Binding Path=MyCollection[Key Name]}
   Binding Expression’s Mode determines the
    direction of data flow.
     OneTime - Once at Load/Parse time
     OneWay (default) - Automatically update target as source
       changes (Read-only data model)
     TwoWay - Automatically update target when source
       changes and update source when target changes
       (Updatable data model)

    UpdateSourceTrigger
     gives you control over when an update actually takes place.
     i.e. Should a source require additional (perhaps lengthy)
     processing before target update.
<object   property=“{   Binding }” …/>
<object   property=“{   Binding propertyPath } …” />
<object   property=“{   Binding oneOrMoreBindingProperties } …” />
<object   property=“{   Binding propertyPath,
                           oneOrMoreBindingProperties } …” />

<object targetProperty= "{Binding sourcePropertyPath,
  oneOrMoreBindingProperties}" .../>

targetProperty must be a DependencyProperty
   Binding Individual Elements
    ◦ DataContext is the default place to look for data
      source. It is inherited in the logical tree. Child
      elements without explicit bindings inherit their
      DataContext from their parent. Best to use it
      when multiple bindings need to use the same
      source.
    ◦ Source Property is used to explicitly specify (or
      override) binding source and path point to
      property.
   For automatic update, the source object
    must implement INotifyPropertyChanged
   Use ItemsSource for Binding collections.
   Automatic collection synchronization requires
    INotifyCollectionChanged implementation on
    source.
   Individual collection elements still need to
    implement INotifyPropertyChanged.
   Note:
    ◦ ObservableCollection<T> automatically implements
      INotifyCollectionChanged.
    ◦ List<T> does not.
   Converters are used to reformat data before presentation.
   Can be used to conditionally alter and control property based
    on bound data.

   Converter is a class that implements IValueConverter
    ◦ Convert() – change data to its native format to display format.
    ◦ ConvertBack() – reverese the process, convert display format back to
      original/native format.
   BindingBase includes 3 properties that help eliminate the
    need for converters in many cases:
    ◦ TargetNullValue – Specifies value to use if bindings results in a null value.
    ◦ StringFormat – Standard .Net string formatting syntax
    ◦ FallBackValue – Value to use upon binding exception/failure (other than
      null return; i.e. invalid source attribute).
   Data Templates
    ◦ Block of XAML used to define how bound objects
      should be displayed.
    ◦ May be included in-line or in resources.
   Validation interfaces
    ◦ IDataErrorInfo
      Single error at a time.
      Not recommended.
    ◦ INotifyDataErrorInfo
      All errors are available.
      Better for Asynchronous operations.


   Target property must specify
    ValidatesOnNotifyDataError.
   Visual Studio
    ◦ Data Binding Designer


   Expression Blend
    ◦ Data Binding Designer
    ◦ Design Time Data
      d:DesignData
      d:DataContext
      d:DesignHeight and d:DesignWidth

Weitere ähnliche Inhalte

Was ist angesagt?

Data Binding and Data Grid View Classes
Data Binding and Data Grid View ClassesData Binding and Data Grid View Classes
Data Binding and Data Grid View ClassesArvind Krishnaa
 
Connecting to a REST API in iOS
Connecting to a REST API in iOSConnecting to a REST API in iOS
Connecting to a REST API in iOSgillygize
 
Advanced Core Data
Advanced Core DataAdvanced Core Data
Advanced Core DataMake School
 
Hibernate Session 1
Hibernate Session 1Hibernate Session 1
Hibernate Session 1b_kathir
 
An Introduction to Spring Data
An Introduction to Spring DataAn Introduction to Spring Data
An Introduction to Spring DataOliver Gierke
 
Intro to IndexedDB (Beta)
Intro to IndexedDB (Beta)Intro to IndexedDB (Beta)
Intro to IndexedDB (Beta)Mike West
 
Hibernate jj
Hibernate jjHibernate jj
Hibernate jjJoe Jacob
 
Using Webservice in iOS
Using Webservice  in iOS Using Webservice  in iOS
Using Webservice in iOS Mahboob Nur
 
Hibernate Basic Concepts - Presentation
Hibernate Basic Concepts - PresentationHibernate Basic Concepts - Presentation
Hibernate Basic Concepts - PresentationKhoa Nguyen
 
ASP.NET Session 11 12
ASP.NET Session 11 12ASP.NET Session 11 12
ASP.NET Session 11 12Sisir Ghosh
 
Web Services with Objective-C
Web Services with Objective-CWeb Services with Objective-C
Web Services with Objective-CJuio Barros
 
mobile in the cloud with diamonds. improved.
mobile in the cloud with diamonds. improved.mobile in the cloud with diamonds. improved.
mobile in the cloud with diamonds. improved.Oleg Shanyuk
 
Query mechanisms for NoSQL databases
Query mechanisms for NoSQL databasesQuery mechanisms for NoSQL databases
Query mechanisms for NoSQL databasesArangoDB Database
 
Quick overview on mongo db
Quick overview on mongo dbQuick overview on mongo db
Quick overview on mongo dbEman Mohamed
 
Change RelationalDB to GraphDB with OrientDB
Change RelationalDB to GraphDB with OrientDBChange RelationalDB to GraphDB with OrientDB
Change RelationalDB to GraphDB with OrientDBApaichon Punopas
 

Was ist angesagt? (20)

Data Binding and Data Grid View Classes
Data Binding and Data Grid View ClassesData Binding and Data Grid View Classes
Data Binding and Data Grid View Classes
 
Hibernate
HibernateHibernate
Hibernate
 
Connecting to a REST API in iOS
Connecting to a REST API in iOSConnecting to a REST API in iOS
Connecting to a REST API in iOS
 
Advanced Core Data
Advanced Core DataAdvanced Core Data
Advanced Core Data
 
Hibernate Session 1
Hibernate Session 1Hibernate Session 1
Hibernate Session 1
 
An Introduction to Spring Data
An Introduction to Spring DataAn Introduction to Spring Data
An Introduction to Spring Data
 
Intro to IndexedDB (Beta)
Intro to IndexedDB (Beta)Intro to IndexedDB (Beta)
Intro to IndexedDB (Beta)
 
ADO.net control
ADO.net controlADO.net control
ADO.net control
 
Hibernate jj
Hibernate jjHibernate jj
Hibernate jj
 
Using Webservice in iOS
Using Webservice  in iOS Using Webservice  in iOS
Using Webservice in iOS
 
ADO.NET
ADO.NETADO.NET
ADO.NET
 
Hibernate Basic Concepts - Presentation
Hibernate Basic Concepts - PresentationHibernate Basic Concepts - Presentation
Hibernate Basic Concepts - Presentation
 
ASP.NET Session 11 12
ASP.NET Session 11 12ASP.NET Session 11 12
ASP.NET Session 11 12
 
Data Bondage in WPF
Data Bondage in WPFData Bondage in WPF
Data Bondage in WPF
 
Web Services with Objective-C
Web Services with Objective-CWeb Services with Objective-C
Web Services with Objective-C
 
mobile in the cloud with diamonds. improved.
mobile in the cloud with diamonds. improved.mobile in the cloud with diamonds. improved.
mobile in the cloud with diamonds. improved.
 
Query mechanisms for NoSQL databases
Query mechanisms for NoSQL databasesQuery mechanisms for NoSQL databases
Query mechanisms for NoSQL databases
 
Quick overview on mongo db
Quick overview on mongo dbQuick overview on mongo db
Quick overview on mongo db
 
Introduction to Hibernate
Introduction to HibernateIntroduction to Hibernate
Introduction to Hibernate
 
Change RelationalDB to GraphDB with OrientDB
Change RelationalDB to GraphDB with OrientDBChange RelationalDB to GraphDB with OrientDB
Change RelationalDB to GraphDB with OrientDB
 

Andere mochten auch

Ольга Дашивец, Агенство путешествий "Ноги в руки"
Ольга Дашивец, Агенство путешествий "Ноги в руки"Ольга Дашивец, Агенство путешествий "Ноги в руки"
Ольга Дашивец, Агенство путешествий "Ноги в руки"Анна Мрук
 
Google Analytics on Steroids: New Features & What You Need to Know
Google Analytics on Steroids: New Features & What You Need to KnowGoogle Analytics on Steroids: New Features & What You Need to Know
Google Analytics on Steroids: New Features & What You Need to KnowEmpirical Path
 
αντίγραφο από 62ο τεύχος εφημερίδας δημοσιογραφικά 29 11 11,prokirikseis 62
αντίγραφο από 62ο τεύχος εφημερίδας δημοσιογραφικά   29 11 11,prokirikseis 62αντίγραφο από 62ο τεύχος εφημερίδας δημοσιογραφικά   29 11 11,prokirikseis 62
αντίγραφο από 62ο τεύχος εφημερίδας δημοσιογραφικά 29 11 11,prokirikseis 62Δημήτριος Κουλόγλου
 
Verb tense
Verb tenseVerb tense
Verb tensesunatcha
 
Knockoutjs databinding
Knockoutjs databindingKnockoutjs databinding
Knockoutjs databindingBoulos Dib
 
Hoover and the depression
Hoover and the depressionHoover and the depression
Hoover and the depressionJustin Hoggard
 
Assignment 10 group assignment final draft
Assignment 10 group assignment final draftAssignment 10 group assignment final draft
Assignment 10 group assignment final draftdebbie14
 
Slaughterhouse 90210 Reflection
Slaughterhouse 90210 ReflectionSlaughterhouse 90210 Reflection
Slaughterhouse 90210 Reflectionleahw418
 
Assignment 12 planning for documentary ( draft 1
Assignment 12  planning for documentary ( draft 1Assignment 12  planning for documentary ( draft 1
Assignment 12 planning for documentary ( draft 1debbie14
 
#2 coursework analysis
#2 coursework analysis#2 coursework analysis
#2 coursework analysisdebbie14
 
Becoming familiar with the outer ear
Becoming familiar with the outer earBecoming familiar with the outer ear
Becoming familiar with the outer earLynn Royer
 
186703099 petrologi-batubara
186703099 petrologi-batubara186703099 petrologi-batubara
186703099 petrologi-batubaraSylvester Saragih
 
Anatomy of a Deportation Case
Anatomy of a Deportation CaseAnatomy of a Deportation Case
Anatomy of a Deportation CaseMarshall Hong
 
Pengantar teknologi mineral3
Pengantar teknologi mineral3Pengantar teknologi mineral3
Pengantar teknologi mineral3Sylvester Saragih
 

Andere mochten auch (20)

Rural mktng
Rural mktngRural mktng
Rural mktng
 
Ольга Дашивец, Агенство путешествий "Ноги в руки"
Ольга Дашивец, Агенство путешествий "Ноги в руки"Ольга Дашивец, Агенство путешествий "Ноги в руки"
Ольга Дашивец, Агенство путешествий "Ноги в руки"
 
Google Analytics on Steroids: New Features & What You Need to Know
Google Analytics on Steroids: New Features & What You Need to KnowGoogle Analytics on Steroids: New Features & What You Need to Know
Google Analytics on Steroids: New Features & What You Need to Know
 
Impressionisme
ImpressionismeImpressionisme
Impressionisme
 
αντίγραφο από 62ο τεύχος εφημερίδας δημοσιογραφικά 29 11 11,prokirikseis 62
αντίγραφο από 62ο τεύχος εφημερίδας δημοσιογραφικά   29 11 11,prokirikseis 62αντίγραφο από 62ο τεύχος εφημερίδας δημοσιογραφικά   29 11 11,prokirikseis 62
αντίγραφο από 62ο τεύχος εφημερίδας δημοσιογραφικά 29 11 11,prokirikseis 62
 
ichigoichie
ichigoichieichigoichie
ichigoichie
 
Verb tense
Verb tenseVerb tense
Verb tense
 
Asteroïden
AsteroïdenAsteroïden
Asteroïden
 
Knockoutjs databinding
Knockoutjs databindingKnockoutjs databinding
Knockoutjs databinding
 
Hoover and the depression
Hoover and the depressionHoover and the depression
Hoover and the depression
 
Assignment 10 group assignment final draft
Assignment 10 group assignment final draftAssignment 10 group assignment final draft
Assignment 10 group assignment final draft
 
Slaughterhouse 90210 Reflection
Slaughterhouse 90210 ReflectionSlaughterhouse 90210 Reflection
Slaughterhouse 90210 Reflection
 
Assignment 12 planning for documentary ( draft 1
Assignment 12  planning for documentary ( draft 1Assignment 12  planning for documentary ( draft 1
Assignment 12 planning for documentary ( draft 1
 
INDUCCION BPM
INDUCCION BPMINDUCCION BPM
INDUCCION BPM
 
#2 coursework analysis
#2 coursework analysis#2 coursework analysis
#2 coursework analysis
 
Becoming familiar with the outer ear
Becoming familiar with the outer earBecoming familiar with the outer ear
Becoming familiar with the outer ear
 
186703099 petrologi-batubara
186703099 petrologi-batubara186703099 petrologi-batubara
186703099 petrologi-batubara
 
Rosbalt.Ru
Rosbalt.RuRosbalt.Ru
Rosbalt.Ru
 
Anatomy of a Deportation Case
Anatomy of a Deportation CaseAnatomy of a Deportation Case
Anatomy of a Deportation Case
 
Pengantar teknologi mineral3
Pengantar teknologi mineral3Pengantar teknologi mineral3
Pengantar teknologi mineral3
 

Ähnlich wie Data Binding in Silverlight

Introduction to XAML and its features
Introduction to XAML and its featuresIntroduction to XAML and its features
Introduction to XAML and its featuresAbhishek Sur
 
The Magic of WPF & MVVM
The Magic of WPF & MVVMThe Magic of WPF & MVVM
The Magic of WPF & MVVMAbhishek Sur
 
Flex3 data binding
Flex3 data bindingFlex3 data binding
Flex3 data bindingguestdf3003
 
WPF DATA BINDING CHEATSHEET V1.1
WPF DATA BINDING CHEATSHEET V1.1WPF DATA BINDING CHEATSHEET V1.1
WPF DATA BINDING CHEATSHEET V1.1Vikas Pandey
 
Web Technologies - forms and actions
Web Technologies -  forms and actionsWeb Technologies -  forms and actions
Web Technologies - forms and actionsAren Zomorodian
 
WPF - Controls &amp; Data
WPF - Controls &amp; DataWPF - Controls &amp; Data
WPF - Controls &amp; DataSharada Gururaj
 
ASP.Net Presentation Part2
ASP.Net Presentation Part2ASP.Net Presentation Part2
ASP.Net Presentation Part2Neeraj Mathur
 
Java Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : DatastoreJava Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : DatastoreIMC Institute
 
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...smn-automate
 
Zend framework 03 - singleton factory data mapper caching logging
Zend framework 03 - singleton factory data mapper caching loggingZend framework 03 - singleton factory data mapper caching logging
Zend framework 03 - singleton factory data mapper caching loggingTricode (part of Dept)
 
App Grid Dev With Coherence
App Grid Dev With CoherenceApp Grid Dev With Coherence
App Grid Dev With CoherenceJames Bayer
 
Application Grid Dev with Coherence
Application Grid Dev with CoherenceApplication Grid Dev with Coherence
Application Grid Dev with CoherenceJames Bayer
 

Ähnlich wie Data Binding in Silverlight (20)

KnockoutJS and MVVM
KnockoutJS and MVVMKnockoutJS and MVVM
KnockoutJS and MVVM
 
Lesson 05 Data Binding in WPF
Lesson 05 Data Binding in WPFLesson 05 Data Binding in WPF
Lesson 05 Data Binding in WPF
 
Introduction to XAML and its features
Introduction to XAML and its featuresIntroduction to XAML and its features
Introduction to XAML and its features
 
The Magic of WPF & MVVM
The Magic of WPF & MVVMThe Magic of WPF & MVVM
The Magic of WPF & MVVM
 
Dev308
Dev308Dev308
Dev308
 
Flex3 data binding
Flex3 data bindingFlex3 data binding
Flex3 data binding
 
WPF DATA BINDING CHEATSHEET V1.1
WPF DATA BINDING CHEATSHEET V1.1WPF DATA BINDING CHEATSHEET V1.1
WPF DATA BINDING CHEATSHEET V1.1
 
Web Technologies - forms and actions
Web Technologies -  forms and actionsWeb Technologies -  forms and actions
Web Technologies - forms and actions
 
WPF and Databases
WPF and DatabasesWPF and Databases
WPF and Databases
 
Ch05 state management
Ch05 state managementCh05 state management
Ch05 state management
 
WPF - Controls &amp; Data
WPF - Controls &amp; DataWPF - Controls &amp; Data
WPF - Controls &amp; Data
 
ASP.NET Lecture 4
ASP.NET Lecture 4ASP.NET Lecture 4
ASP.NET Lecture 4
 
ASP.Net Presentation Part2
ASP.Net Presentation Part2ASP.Net Presentation Part2
ASP.Net Presentation Part2
 
Practical OData
Practical ODataPractical OData
Practical OData
 
Java Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : DatastoreJava Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : Datastore
 
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
 
Zend framework 03 - singleton factory data mapper caching logging
Zend framework 03 - singleton factory data mapper caching loggingZend framework 03 - singleton factory data mapper caching logging
Zend framework 03 - singleton factory data mapper caching logging
 
Introduction to Datastore
Introduction to DatastoreIntroduction to Datastore
Introduction to Datastore
 
App Grid Dev With Coherence
App Grid Dev With CoherenceApp Grid Dev With Coherence
App Grid Dev With Coherence
 
Application Grid Dev with Coherence
Application Grid Dev with CoherenceApplication Grid Dev with Coherence
Application Grid Dev with Coherence
 

Kürzlich hochgeladen

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 

Kürzlich hochgeladen (20)

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 

Data Binding in Silverlight

  • 1. Boulos Dib Independent Consultant Napeague Inc. February 10, 2011
  • 2. A Silverlight infrastructure to connect business model with UI Controls.  Data Binding is not about data access, data controls, data layer, data models or databases.  Not unique to Silverlight. Other technologies implement data binding: ASP.NET, Adobe Flex, WPF  The System.Windows.Data.Binding class is used to make the connection .
  • 3. Binding connection is defined by 3 elements: ◦ Source of the data (CLR Object) ◦ Binding Mode (Direction of flow) ◦ Target for the data (Dependency Property)  Value Converters enhance or override binding; an extensibility point.
  • 4. TextBox in XAML  <TextBox x:Name=“myTextBox” />  Binding via code-behind  DateTime currentTime = DateTime.Now;  Binding binding = new Binding(“TimeOfDay”);  binding.Source = currentTime;  binding.Mode = BindingMode.OneWay;  myTextBox.SetBinding(TextBox.TextProperty, binding);  Unbind a data source (code only)  myTextBox.Text = “Binding Removed”;
  • 5. TextBox in XAML (Binding Expression) <TextBox x:Name=“myTextBox” Text=“{Binding TimeOfDay, Mode=OneWay}” /> ---or--- <TextBox x:Name=“myTextBox” Text=“{Binding Path=TimeOfDay, Mode=OneWay}” />  Alternate - Object Element Syntax <TextBox x:Name=“myTextBox”> <TextBox.Text> <Binding Path=“TimeOfDay” Mode=“OneWay” /> </TextBox.Text> </TextBox>
  • 6. ElementName  Source property  RelativeSource property ◦ Self ◦ TemplateParent  Or  If not set, the source is implicitly set via inherited DataContext.
  • 7. Simple property ◦ {Binding ElementName=LayoutRoot, Path=myProperty}  Nested Property ◦ {Binding ElementName=LayoutRoot, Path=Background.Color}  Collection – set the Path to current item ◦ {Binding Path=myCollection.CurrentItem.Property}  Item in a collection - use indexer ◦ {Binding Path=MyCollection[0]} ◦ Or ◦ {Binding Path=MyCollection[Key Name]}
  • 8. Binding Expression’s Mode determines the direction of data flow. OneTime - Once at Load/Parse time OneWay (default) - Automatically update target as source changes (Read-only data model) TwoWay - Automatically update target when source changes and update source when target changes (Updatable data model) UpdateSourceTrigger gives you control over when an update actually takes place. i.e. Should a source require additional (perhaps lengthy) processing before target update.
  • 9. <object property=“{ Binding }” …/> <object property=“{ Binding propertyPath } …” /> <object property=“{ Binding oneOrMoreBindingProperties } …” /> <object property=“{ Binding propertyPath, oneOrMoreBindingProperties } …” /> <object targetProperty= "{Binding sourcePropertyPath, oneOrMoreBindingProperties}" .../> targetProperty must be a DependencyProperty
  • 10. Binding Individual Elements ◦ DataContext is the default place to look for data source. It is inherited in the logical tree. Child elements without explicit bindings inherit their DataContext from their parent. Best to use it when multiple bindings need to use the same source. ◦ Source Property is used to explicitly specify (or override) binding source and path point to property.  For automatic update, the source object must implement INotifyPropertyChanged
  • 11. Use ItemsSource for Binding collections.  Automatic collection synchronization requires INotifyCollectionChanged implementation on source.  Individual collection elements still need to implement INotifyPropertyChanged.  Note: ◦ ObservableCollection<T> automatically implements INotifyCollectionChanged. ◦ List<T> does not.
  • 12. Converters are used to reformat data before presentation.  Can be used to conditionally alter and control property based on bound data.  Converter is a class that implements IValueConverter ◦ Convert() – change data to its native format to display format. ◦ ConvertBack() – reverese the process, convert display format back to original/native format.  BindingBase includes 3 properties that help eliminate the need for converters in many cases: ◦ TargetNullValue – Specifies value to use if bindings results in a null value. ◦ StringFormat – Standard .Net string formatting syntax ◦ FallBackValue – Value to use upon binding exception/failure (other than null return; i.e. invalid source attribute).
  • 13. Data Templates ◦ Block of XAML used to define how bound objects should be displayed. ◦ May be included in-line or in resources.
  • 14. Validation interfaces ◦ IDataErrorInfo  Single error at a time.  Not recommended. ◦ INotifyDataErrorInfo  All errors are available.  Better for Asynchronous operations.  Target property must specify ValidatesOnNotifyDataError.
  • 15. Visual Studio ◦ Data Binding Designer  Expression Blend ◦ Data Binding Designer ◦ Design Time Data  d:DesignData  d:DataContext  d:DesignHeight and d:DesignWidth