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 8264473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:28:11+00:00 2026-06-08T04:28:11+00:00

I have two Datagrids. You can switch Items between it by Doubleclinking on one

  • 0

I have two Datagrids. You can switch Items between it by Doubleclinking on one or more rows.
The doubleclick event is handled by a command sending the list of selected items to the viewmodel.

So i have Datagrid 1 with Trigger:

<i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseDoubleClick" SourceName="lstProducts">
                    <cmd:EventToCommand Command="{Binding Path=Add}" 
                                        CommandParameter="{Binding ElementName=lstProducts, Path=SelectedItems}" />
                </i:EventTrigger>
</i:Interaction.Triggers>

And Datagrid 2 Trigger:

<i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseDoubleClick"  SourceName="dgProducts">
                    <cmd:EventToCommand Command="{Binding Path=Remove}"
                                    CommandParameter="{Binding ElementName=dgProducts,Path=SelectedItems}" />
                </i:EventTrigger>
            </i:Interaction.Triggers>

Everytime I double Click on a Datagrid it calls the Add AND Remove Command. But when I set a debug Point inside both delegate Command Methods it only enters one. If I set it in only one, no matter which one, it will enter it.

For example having clicked in the first datagrid it should call the Add Command, so it stops at the breakpoint. But also when I set the breakpoint to remove, but not on both.

I tried to apply the SourceName and even the SourceObject but it wont help..

Maybe anyone knows how to fix this?

  • 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-06-08T04:28:13+00:00Added an answer on June 8, 2026 at 4:28 am

    I think I have your scenario working properly:

    public partial class MainWindow : Window
    {
        public ObservableCollection<Product> Added { get; set; }
    
        public ObservableCollection<Product> Available { get; set; }
    
        public ICommand Add { get; set; }
    
        public ICommand Remove { get; set; }
    
        public MainWindow()
        {
            Added = new ObservableCollection<Product>();
            Available = new ObservableCollection<Product>();
            Available.Add(new Product { Id = 1 });
            Available.Add(new Product { Id = 2 });
            Available.Add(new Product { Id = 3 });
            Available.Add(new Product { Id = 4 });
            Available.Add(new Product { Id = 5 });
            InitializeComponent();
            DataContext = this;
    
            Add = new RelayCommand<IEnumerable>(x =>
            {
                foreach (Product item in x.Cast<Product>().ToArray())
                {
                    Added.Add(item);
                    Available.Remove(item);
                }
    
                Console.WriteLine("add");
            });
    
            Remove = new RelayCommand<IEnumerable>(x =>
            {
                foreach (Product item in x.Cast<Product>().ToArray())
                {
                    Added.Remove(item);
                    Available.Add(item);
                }
                Console.WriteLine("remove");
            });
        }
    }
    
    public class Product
    {
        public int Id { get; set; }
    }
    

    and xaml:

    <StackPanel >
    
        <DataGrid ItemsSource="{Binding Available}" SelectionUnit="FullRow" x:Name="lstProducts">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseDoubleClick" SourceName="lstProducts">
                    <cmd:EventToCommand Command="{Binding Path=Add}"
                                        CommandParameter="{Binding ElementName=lstProducts, Path=SelectedItems}" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
    
        </DataGrid>
    
        <DataGrid ItemsSource="{Binding Added}" SelectionUnit="FullRow" x:Name="lstProductsAdded" >
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseDoubleClick" SourceName="lstProductsAdded">
                    <cmd:EventToCommand Command="{Binding Path=Remove}"
                                        CommandParameter="{Binding ElementName=lstProductsAdded, Path=SelectedItems}" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
    
        </DataGrid>
    
    </StackPanel>
    

    Is this what you did/wanted to do? In my sample just one command is executed. And you can see it in Output window.

    I figured out how to break this code to reproduce your behavior: in both i:EventTrigger tags you have the same SoruceName so you bind to single grid.

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

Sidebar

Related Questions

Can i add two header text in Datagrid? My Requirement is to have two
Have two actionsheet buttons and one modalviewcontroller on mainviewcontroller in application. Now for two
I have two classes (MVC view model) which inherits from one abstract base class.
I have two columns say Main and Sub . (they can be of same
I have a DataGrid a user can add items to by entering data in
I have an Application with two Tabs in WPF. One is Used to add
I have two silverlight (2 or 3) datagrids (from the July 2009 Silverlight toolkit)
I have a WPF application with two DataGrids that share the same ItemsSource. When
I have some DataGrids with pretty standard one-line itemrenderers, but need to use a
I have an AIR application with two DataGrids that I would like to export

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.