Target: dependency property Source: any public property CLR and WPF properties Target: dependency...
-
Upload
samantha-wilcox -
Category
Documents
-
view
252 -
download
4
Transcript of Target: dependency property Source: any public property CLR and WPF properties Target: dependency...
![Page 1: Target: dependency property Source: any public property CLR and WPF properties Target: dependency property Source: any public property CLR and WPF properties.](https://reader031.fdocuments.in/reader031/viewer/2022020714/56649e4d5503460f94b42fda/html5/thumbnails/1.jpg)
Bring Your Data to Life with Windows Presentation FoundationAnson TsaoSenior Program ManagerMicrosoft Corporation
![Page 2: Target: dependency property Source: any public property CLR and WPF properties Target: dependency property Source: any public property CLR and WPF properties.](https://reader031.fdocuments.in/reader031/viewer/2022020714/56649e4d5503460f94b42fda/html5/thumbnails/2.jpg)
Data is Everywhere
![Page 3: Target: dependency property Source: any public property CLR and WPF properties Target: dependency property Source: any public property CLR and WPF properties.](https://reader031.fdocuments.in/reader031/viewer/2022020714/56649e4d5503460f94b42fda/html5/thumbnails/3.jpg)
What is Data Binding?
Target: dependency propertySource: any public property
CLR and WPF properties
Target: dependency propertySource: any public property
CLR and WPF properties
Control
“Data Item” Source
Property
Binding
Targ
et
Pro
perty
ADO.NETXML
CLR ObjectsLINQ
Web ServicesWPF Elements
![Page 4: Target: dependency property Source: any public property CLR and WPF properties Target: dependency property Source: any public property CLR and WPF properties.](https://reader031.fdocuments.in/reader031/viewer/2022020714/56649e4d5503460f94b42fda/html5/thumbnails/4.jpg)
Basic Data Binding
demo
![Page 5: Target: dependency property Source: any public property CLR and WPF properties Target: dependency property Source: any public property CLR and WPF properties.](https://reader031.fdocuments.in/reader031/viewer/2022020714/56649e4d5503460f94b42fda/html5/thumbnails/5.jpg)
Object Data Providers
Add to resource dictionaryNamed source objects
Use with resource binding{StaticResource solarSystem}
<Window> <Window.Resources> <ObjectDataProvider x:Key=“solarSystem” ObjectType=“{x:Type l:SolarSystem}" /> </Window.Resources>
...
<TextBlock TextContent="{Binding Path=Sun.Name, Source={StaticResource solarSystem} }" />
![Page 6: Target: dependency property Source: any public property CLR and WPF properties Target: dependency property Source: any public property CLR and WPF properties.](https://reader031.fdocuments.in/reader031/viewer/2022020714/56649e4d5503460f94b42fda/html5/thumbnails/6.jpg)
Text= {Binding Path=Sun.Name Source={StaticResource solarSystem}}
Source= {Binding Path=Sun.Image Source={StaticResource solarSystem}}
Share Common Source
StackPanel
Image
TextBox
DataContext= {Binding Path=Sun Source={StaticResource solarSystem}}
Text= {Binding Path=Name}
Source= {Binding Path=Image}
DataContext= {Binding Path=SunAndPlanets[3] Source={StaticResource solarSystem}}
![Page 7: Target: dependency property Source: any public property CLR and WPF properties Target: dependency property Source: any public property CLR and WPF properties.](https://reader031.fdocuments.in/reader031/viewer/2022020714/56649e4d5503460f94b42fda/html5/thumbnails/7.jpg)
Change Notification
demo
![Page 8: Target: dependency property Source: any public property CLR and WPF properties Target: dependency property Source: any public property CLR and WPF properties.](https://reader031.fdocuments.in/reader031/viewer/2022020714/56649e4d5503460f94b42fda/html5/thumbnails/8.jpg)
Change Notification
Property ChangesINotifyPropertyChanged PropertyChanged event pattern
Collection ChangesINotifyCollectionChangedObseverableCollection<T>BindingList<T>
![Page 9: Target: dependency property Source: any public property CLR and WPF properties Target: dependency property Source: any public property CLR and WPF properties.](https://reader031.fdocuments.in/reader031/viewer/2022020714/56649e4d5503460f94b42fda/html5/thumbnails/9.jpg)
Binding to a Collection
demo
![Page 10: Target: dependency property Source: any public property CLR and WPF properties Target: dependency property Source: any public property CLR and WPF properties.](https://reader031.fdocuments.in/reader031/viewer/2022020714/56649e4d5503460f94b42fda/html5/thumbnails/10.jpg)
Data Templates
class SolarSystemObject{ Uri Image {get;set} string Name {get;set}}
<DataTemplate x:Key="BetterSunAndPlanetsTemplate">
<Border> <StackPanel> <Image Source="{Binding Path=Image}" />
<TextBlock Text="{Binding Path=Name}" /> </Border> </StackPanel> </Border></DataTemplate>
<ControlTemplate><Grid> <ContentPresenter/></Grid>
</ControlTemplate>
![Page 11: Target: dependency property Source: any public property CLR and WPF properties Target: dependency property Source: any public property CLR and WPF properties.](https://reader031.fdocuments.in/reader031/viewer/2022020714/56649e4d5503460f94b42fda/html5/thumbnails/11.jpg)
Choosing a Data Template
By name (resource dictionary key)ContentTemplate/ItemTemplate= {StaticResource myStyle}
By type<DataTemplate DataType="{x:Type cc:Sun}"><DataTemplate DataType="Book"> for XML
![Page 12: Target: dependency property Source: any public property CLR and WPF properties Target: dependency property Source: any public property CLR and WPF properties.](https://reader031.fdocuments.in/reader031/viewer/2022020714/56649e4d5503460f94b42fda/html5/thumbnails/12.jpg)
Fancy Data Templates
demo
![Page 13: Target: dependency property Source: any public property CLR and WPF properties Target: dependency property Source: any public property CLR and WPF properties.](https://reader031.fdocuments.in/reader031/viewer/2022020714/56649e4d5503460f94b42fda/html5/thumbnails/13.jpg)
Collection Views
demo
![Page 14: Target: dependency property Source: any public property CLR and WPF properties Target: dependency property Source: any public property CLR and WPF properties.](https://reader031.fdocuments.in/reader031/viewer/2022020714/56649e4d5503460f94b42fda/html5/thumbnails/14.jpg)
Collection Views
Wraps the Underlying CollectionSortingFilteringGroupingSelection
ItemsControl create default CollectionViewCollectionViewSource creates a CollectionView in XAML
Allows Grouping, Sorting etc in MarkupContains Source and View Properties
Not available in Silverlight 2
![Page 15: Target: dependency property Source: any public property CLR and WPF properties Target: dependency property Source: any public property CLR and WPF properties.](https://reader031.fdocuments.in/reader031/viewer/2022020714/56649e4d5503460f94b42fda/html5/thumbnails/15.jpg)
Master-Details
demo
![Page 16: Target: dependency property Source: any public property CLR and WPF properties Target: dependency property Source: any public property CLR and WPF properties.](https://reader031.fdocuments.in/reader031/viewer/2022020714/56649e4d5503460f94b42fda/html5/thumbnails/16.jpg)
Master Details
Use ItemsControl (e.g. ListBox) as master
Set IsSynchronizedWithCurrentItem="True"
Other bindings on same source will follow master
Alternative: bind to selected item/value
{Binding Path=SelectedValue.Name, ElementName=myListBox }Fragile on UI changes
![Page 17: Target: dependency property Source: any public property CLR and WPF properties Target: dependency property Source: any public property CLR and WPF properties.](https://reader031.fdocuments.in/reader031/viewer/2022020714/56649e4d5503460f94b42fda/html5/thumbnails/17.jpg)
Hierarchial Data
demo
![Page 18: Target: dependency property Source: any public property CLR and WPF properties Target: dependency property Source: any public property CLR and WPF properties.](https://reader031.fdocuments.in/reader031/viewer/2022020714/56649e4d5503460f94b42fda/html5/thumbnails/18.jpg)
Hierarchical Binding<Foo xmlns=''> <Quux> <Wibble /> </Quux> <Bar /> <Spong> <Ick /> <Iyck/> <Baz /> </Spong></Foo>
<TreeView ItemsSource="{Binding XPath='/*'}"> <TreeView.ItemTemplate> <HierarchicalDataTemplate ItemsSource="{Binding XPath='*'}"> <TextBlock Text="{Binding Path=Name}"/> </HierarchicalDataTemplate> </TreeView.ItemTemplate></TreeView>
![Page 19: Target: dependency property Source: any public property CLR and WPF properties Target: dependency property Source: any public property CLR and WPF properties.](https://reader031.fdocuments.in/reader031/viewer/2022020714/56649e4d5503460f94b42fda/html5/thumbnails/19.jpg)
What’s new in 3.5
New Debugging MechanismSupport for IDataErrorInfoAlternative Syntax for Data ValidationLINQ Support
![Page 20: Target: dependency property Source: any public property CLR and WPF properties Target: dependency property Source: any public property CLR and WPF properties.](https://reader031.fdocuments.in/reader031/viewer/2022020714/56649e4d5503460f94b42fda/html5/thumbnails/20.jpg)
Summary
WPF understands your dataUse your favorite data model: XML, objects, SQL, LINQ, WS, …Bind data to controls
Templates give your data a face
Controls “think” data Data is pervasive across and integrated into the platform
![Page 21: Target: dependency property Source: any public property CLR and WPF properties Target: dependency property Source: any public property CLR and WPF properties.](https://reader031.fdocuments.in/reader031/viewer/2022020714/56649e4d5503460f94b42fda/html5/thumbnails/21.jpg)
Questions
![Page 22: Target: dependency property Source: any public property CLR and WPF properties Target: dependency property Source: any public property CLR and WPF properties.](https://reader031.fdocuments.in/reader031/viewer/2022020714/56649e4d5503460f94b42fda/html5/thumbnails/22.jpg)
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.
The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after
the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
![Page 23: Target: dependency property Source: any public property CLR and WPF properties Target: dependency property Source: any public property CLR and WPF properties.](https://reader031.fdocuments.in/reader031/viewer/2022020714/56649e4d5503460f94b42fda/html5/thumbnails/23.jpg)