[英]WPF Binding RelativeSource issue
I'm using FindAncestor and AncestorLevel=3 to reach to the top level tag which should have the viewModel relay command, but it doesnt work. 我正在使用FindAncestor和AncestorLevel = 3到达应该具有viewModel relay命令的顶级标签,但是它不起作用。 Any suggestions if I am doing it wrong or a way to debug this scenario? 如果我做错了或调试此方案的方式有什么建议吗?
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding name}" Cursor="Hand"
Foreground="Blue" TextDecorations="Underline">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDown">
<cmd:EventToCommand Command="{Binding NameClickCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=Grid, AncestorLevel=3}}"
MustToggleIsEnabled="True" PassEventArgsToCommand="True"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
It seems like you're binding the Command to a property called NameClickCommand on a Grid. 似乎您正在将Command绑定到网格上名为NameClickCommand的属性。 Grid doesn't have this property, so try to change it to 网格没有此属性,因此请尝试将其更改为
Command="{Binding Path=DataContext.NameClickCommand...
if the NameClickCommand is in the DataContext of the Grid 如果NameClickCommand在网格的DataContext中
You're looking for the 3rd Grid
up the hierarchy -- is that what you want? 您正在寻找层次结构中的第三个Grid
-这就是您想要的吗?
Note that Grid
does not include DataGrid
. 请注意, Grid
不包括DataGrid
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.