[英]WPF Binding RelativeSource issue
我正在使用FindAncestor和AncestorLevel = 3到達應該具有viewModel relay命令的頂級標簽,但是它不起作用。 如果我做錯了或調試此方案的方式有什么建議嗎?
<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>
似乎您正在將Command綁定到網格上名為NameClickCommand的屬性。 網格沒有此屬性,因此請嘗試將其更改為
Command="{Binding Path=DataContext.NameClickCommand...
如果NameClickCommand在網格的DataContext中
您正在尋找層次結構中的第三個Grid
-這就是您想要的嗎?
請注意, Grid
不包括DataGrid
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.