SlideShare une entreprise Scribd logo
1  sur  15
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

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
 

Tendances (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
 

En vedette

Ольга Дашивец, Агенство путешествий "Ноги в руки"
Ольга Дашивец, Агенство путешествий "Ноги в руки"Ольга Дашивец, Агенство путешествий "Ноги в руки"
Ольга Дашивец, Агенство путешествий "Ноги в руки"Анна Мрук
 
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
 

En vedette (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
 

Similaire à 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
 

Similaire à 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
 

Dernier

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 

Dernier (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

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