您的位置:首页 > 其它

各种情况下 Data Binding 总结

2010-08-18 14:58 183 查看
绑定到另一个控件的属性

<StackPanel>
<TextBox x:Name="theTextBox"/>
<TextBlock Text="{Binding Text, ElementName=theTextBox}"/>
</StackPanel>


上面这个例子,TextBlock的内容绑定了TextBox,当在TextBox里输入文本是,TextBlock也同时显示

---
绑定到 RelativeSource


<ListBox ItemsSource="{Binding MyDataSrc}" Width="200" Padding="0">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Width="{Binding Path=ActualWidth, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBoxItem}}">
<Button Content="{Binding}"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>





{Binding Path=xxx, RelativeSource={RelativeSource Self}}
{Binding Path=xxx, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type typeXXX}}}
{Binding Path=xxx, RelativeSource={RelativeSource TemplatedParent}}
{TemplateBinding Path=xxx}



---

参考阅读:
http://stackoverflow.com/questions/84278/how-do-i-use-wpf-bindings-with-relativesource
http://www.nbdtech.com/Free/WpfBinding.pdf

---
To be continued ...
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: