我有 2 个数据模板。
第一个包含网格,第二个包含按钮。
我需要将按钮的命令参数作为选定的网格项发送。
我怎样才能做到这一点 ?
<ObjectDataProvider x:Key="Datas" ObjectType="{x:Type ViewModel:UserControlViewModel}"></ObjectDataProvider>
<DataTemplate x:Key="SourceGrid">
<WPFToolKit:DataGrid x:Name="SourceDataGrid" ItemsSource="{Binding Source={StaticResource Datas},Path=SourceGridData}" CanUserSortColumns="True" GridLinesVisibility="None" IsSynchronizedWithCurrentItem="True" SelectionUnit="FullRow"></WPFToolKit:DataGrid>
</DataTemplate>
<DataTemplate x:Key="AddRemoveDataTemplate">
<StackPanel>
<Button Name="Add" Content="Add">
<Button.Command>
<Binding Source="{StaticResource Datas}" Path="AddCommand">
</Binding>
</Button.Command>
<Binding ElementName="SourceDataGrid" Path="SelectedItem"></Binding>
</Button.CommandParameter>
</Button>
<StackPanel>
</DataTemplate>
你可以尝试使用Binding
与RelativeSource
属性设置为FindAncestor
模式并寻找DataGrid
目的。但是,我不确定它是否适用于您的场景,因为我不知道这些如何DataTemplate
s 彼此相关。是第二个DataTemplate
用于中的项目DataGrid
?!
不知何故,你的设计让我感觉很奇怪。您确定需要吗DataTemplate
两种情况下都是吗?您究竟想实现什么目标?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)