1 / 25

WPF Data Binding

WPF Data Binding. Tomer Shamam Smart Client Team Leader Sela Group tomer@sela.co.il http://blogs.microsoft.co.il/blogs/tomershamam. Agenda. WPF in a Nutshell Today’s Data-View Data Binding Concept Handling Data Changes Value Conversion Collection Data Binding Data Validation

mavis
Download Presentation

WPF Data Binding

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. WPF Data Binding Tomer Shamam Smart Client Team Leader Sela Group tomer@sela.co.il http://blogs.microsoft.co.il/blogs/tomershamam

  2. Agenda • WPF in a Nutshell • Today’s Data-View • Data Binding Concept • Handling Data Changes • Value Conversion • Collection Data Binding • Data Validation • Trace and Debug • Data Visualization • New in .NET 3.5 SP1 • Limitations

  3. WPF in a Nutshell

  4. Today’s Data-View UI Add to ListBox Register Events Set Data Load Get Data CeateListBoxItem Data Binding Logic Data Changed Set Move Update Collection Data Arrived Get Data Data Register Events <Aquarium> <Thermometer/> <Fish/> <Fish/> </ Aquarium > Database Services XML

  5. Data Binding in Action View Data Binding Target Binding Source Dependency Property Property Data Binding One Way Initialize Target Two Way Update Target Update Source One Time Validate Errors One Way To Source Convert Data

  6. Data Binding in Action

  7. Handling Data Changes Socket socket = …; View view = …; Binding binding = …; ... socket.IsActive = true; IsActive = Socket true false Binding Changed

  8. Property Change Mechanisms • INotifyPropertyChanged interface • <Property>Changed event pattern • PropertyDescriptor value changed • WPF DependencyProperty

  9. Handling Data Changes

  10. Two-way Value Conversion INotifyPropertyChanged IValueConverter Fahrenheit Celsius Converter + Temperature Site Temperature Brush Converter IValueConverter

  11. Data Binding Converters

  12. Collection Data Binding <ListView ItemsSource=“{Binding}” /> SingleSocket Collection<Automation> RangeSwitch Sort () Filter() Group() CollectionView OnOffSwitch SingleSocket

  13. Collection Binding

  14. Data Validation • User input validation in WPF is done through Binding • Three options to validate input: • ExceptionValidationRule • IDataErrorInfo • Custom Validation Rule <Binding Source="{StaticResource data}" Path="Age"          UpdateSourceTrigger="PropertyChanged"> <Binding.ValidationRules>         <ExceptionValidationRule/>     </Binding.ValidationRules> </Binding>

  15. Validating User input

  16. Trace and Debug • Binding throws exceptions on critical errors • Path spelling mistakes are traced • Binding errors are traceable C# TraceListener listener = new XxxWriterTraceListener(...); PresentationTraceSources.DataBindingSource.Listeners.Add( listener); <system.diagnostics> <sources> <source name="System.Windows.Data" switchName=“..."> ... </sources> </system.diagnostics> App.config

  17. Data Binding Tracing

  18. Data Visualization SingleSocket RangeSwitch Binding OnOffSwitch SingleSocket Collection<Automation>

  19. Data Visualization

  20. Limitations • Data Binding is Untyped • Target is limited to DependencyObject • No multithreaded support for Collection Binding • Data Template parts are Hard to Get! • Interface-specific Data Template is not supported • Blend data-binding support is limited

  21. New in .NET 3.5 SP1 • StringFormat support within {{ Binding }} expressions • New alternating rows support in ItemsControl • Better handling for null in editable controls • Item-level validation • MultiSelector support • IEditableCollectionView support • Performance improvements with IEnumerable

  22. Summary • New Design Approach • Data-View Decoupling • Better Development Experience • Eliminates Boilerplate Code • Try it now…

  23. Resources Data Binding on MSDN http://msdn2.microsoft.com/en-us/library/ms750612.aspx Windows Client .NET http://windowsclient.net/ Beatriz Costa Blog http://www.beacosta.com/blog/ My Blog http://blogs.microsoft.co.il/blogs/tomershamam/

  24. Don’t work too hard! Data Binding It works for You! © 2007 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.

More Related