开发者

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. 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="{B开发者_开发技巧inding 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. 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


You're looking for the 3rd Grid up the hierarchy -- is that what you want?

Note that Grid does not include DataGrid.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜