RelativeSource属性 https://blog.csdn.net/yangwenxue1989/article/details/81624240

Binding时,如果明确知道数据源的Name,就能用Source或者ElementName进行绑定,但是有时候我们需要绑定的数据源可能没有明确的Name,此时我们就需要利用Binding的RelativeSource进行绑定,这种办法的意思是指当前元素和绑定源的位置关系。(其实就是绝对位置、相对位置)

 <!--CheckBox的IsChecked属性,绑定自定义的IsSelected属性,状态会被PropertyChanged触发改变-->
 <CheckBox IsChecked="{Binding Path=IsSelected,  UpdateSourceTrigger=PropertyChanged}"
           VerticalAlignment="Center" HorizontalAlignment="Center"
           Command="{Binding Path=DataContext.SelectMenuItemCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGrid}}}" />

绑定的时候,有时候需要用DataContext.属性,原因参考http://www.bubuko.com/infodetail-1304649.html

 

相关文章:

  • 2022-12-23
  • 2022-01-06
  • 2022-02-23
  • 2022-01-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-19
  • 2022-12-23
  • 2021-06-20
相关资源
相似解决方案