I have 2 Datatemplates.
One contain a grid , second one contain a button.
I need to send command parameters of button as selected grid items.
How can i do this ?
<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>
You could try to use a
Bindingwith theRelativeSourceproperty set to theFindAncestormode and looking for aDataGridobject. However, I am not sure whether it will work in your scenario because I do not know how theseDataTemplates are related to each other. Is the secondDataTemplateused for the items in theDataGrid?!Somehow, your design feels strange to me. Are you sure that you need
DataTemplates in both cases? What exactly do you want to achieve?