如何在XAML中获取WPF数据网格的当前选定行索引。我知道如何在代码后面获取当前行索引。但是我想获取选定的行索引以将其作为命令参数传递,以便我可以从集合中删除相应的项,并传递索引。
我试过了CommandParameter="{Binding Items.CurrentPosition, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
,但是不起作用(给-1作为selectedindex)。是否可以在XAML中获取当前行索引,如果可以,如何?
这对我来说很好,我在一行中的按钮上使用了它:
Command="{Binding Path=DataContext.MyClickRowEventCommand,
RelativeSource= {RelativeSource FindAncestor,
AncestorType={x:Type DataGrid}}}"
CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self}, Path=DataContext}"
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句