各种情况下 Data Binding 总结

时间:2022-10-02 18:43:55
绑定到另一个控件的属性
   
   
   
< 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}
---
参考阅读:
 
---
To be continued ...