Nothing is everything.

Tuesday, January 5, 2010

WPF Data Binding - xaml

<Grid.Resources>
<
collection:ArrayList x:Key="photos"/>
</
Grid.Resources>
<!--Bind to element mainPate-->
<TextBlock Text="{Binding ElementName=mainPage, Path=Title}"/>
<!--Bind to self-->
<TextBlock Text="{Binding RelativeSource={RelativeSource Self}, Path=Background}"/>
<!--Bind to its TemplatedParent property-->
<TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}}"/>
<!--Bind to an ancestor-->
<TextBlock Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorLevel=2, AncestorType={x:Type TypeName=TreeView}}}"/>
<!--Bind to the previous data.-->
<TextBlock Text="{Binding RelativeSource={RelativeSource PreviousData}}"/>
<!--Bind to a resourc, one-way binding unless photos's type implements INotifyPropertyChanged-->
<!--WPF has an inner collection class which implements INotifyPropertyChanged-->
<TextBlock Text="{Binding Source={StaticResource photos}, Path=Count}"/>

<!--binding source can be of any type, target can only be dependency objects-->

No comments:

Post a Comment

Followers