WPF Data Binding Tomer Shamam Smart Client Team Leader Sela Group
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
WPF in a Nutshell
Today’s Data-View Set Move Load
Data Binding in Action One Way Two Way One Time One WayTo Source
Data Binding in Action
Handling Data Changes Socket socket = …; View view = …; Binding binding = …;... socket.IsActive = true; Socket socket = …; View view = …; Binding binding = …;... socket.IsActive = true; IsActive = Socket false Changed true
Property Change Mechanisms INotifyPropertyChanged interface Changed event pattern PropertyDescriptor value changed WPF DependencyProperty
Handling Data Changes
+ Temperature Site INotifyPropertyChanged Two-way Value Conversion Temperature Brush Converter Temperature Brush Converter Fahrenheit Celsius Converter Fahrenheit Celsius Converter
Data Binding Converters
Collection Data Binding Collection SingleSocket <ListView ItemsSource=“{Binding}” /> ItemsSource=“{Binding}” /><ListView Sort () Filter() Group() Sort () Filter() Group() CollectionView OnOffSwitch RangeSwitch SingleSocket
Collection Binding
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">
Validating User input
Trace and Debug Binding throws exceptions on critical errors Path spelling mistakes are traced Binding errors are traceable TraceListener listener = new XxxWriterTraceListener(...); PresentationTraceSources.DataBindingSource.Listeners.Add( listener);... C# App.config
Data Binding Tracing
Data Visualization Collection SingleSocket OnOffSwitch RangeSwitch SingleSocket
Data Visualization
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
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
Summary New Design Approach Data-View Decoupling Better Development Experience Eliminates Boilerplate Code Try it now…
Resources Data Binding on MSDN us/library/ms aspx us/library/ms aspx Windows Client.NET Beatriz Costa Blog My Blog shamam/ shamam/
© 2007 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.