Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 817477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:00:01+00:00 2026-05-15T02:00:01+00:00

I have 2 Datatemplates. One contain a grid , second one contain a button.

  • 0

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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T02:00:02+00:00Added an answer on May 15, 2026 at 2:00 am

    You could try to use a Binding with the RelativeSource property set to the FindAncestor mode and looking for a DataGrid object. However, I am not sure whether it will work in your scenario because I do not know how these DataTemplates are related to each other. Is the second DataTemplate used for the items in the DataGrid?!

    Somehow, your design feels strange to me. Are you sure that you need DataTemplates in both cases? What exactly do you want to achieve?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have searched high and low, but I can't figure this one out. I
I need bind some ComboBoxes to one ObservableCollection. I have this ListView . <ListView
In my application, I would like to have DataTemplates such that I can say:
I have a WPF form that contains a DataGrid. This DataGrid is editable. One
I want to have different datatemplates within a single listbox. For example I need
I am having one view where I need to display some Grid and TabControl.
I have few layouts (different DataTemplates) with video controls. Creation of this video controls
I have a listbox where the items contain checkboxes: <ListBox Style={StaticResource CheckBoxListStyle} Name=EditListBox> <ListBox.ItemTemplate>
Couldn't find an answer to this one. I have a WPF ListView control that
I've tried searching up and down for this but can't find anything. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.