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

  • Home
  • SEARCH
  • 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 1099685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:46:12+00:00 2026-05-17T00:46:12+00:00

This code works fine : <sdk:DataGrid ItemsSource={Binding MyItems} SelectedItem={Binding MySelectedItem,Mode=TwoWay} x:Name=dataGrid> <i:Interaction.Triggers> <i:EventTrigger EventName=SelectionChanged>

  • 0

This code works fine :

<sdk:DataGrid ItemsSource="{Binding MyItems}" SelectedItem="{Binding MySelectedItem,Mode=TwoWay}" x:Name="dataGrid">
    <i:Interaction.Triggers>
            <i:EventTrigger EventName="SelectionChanged">
                    <i:InvokeCommandAction Command="{Binding CommandName}" CommandParameter="{Binding ElementName=MainTabControl,Mode=OneWay}"/>
            </i:EventTrigger>
    </i:Interaction.Triggers>

In my CustomDataGrid the Command executes but the CommandParameter is null :

<customControl:CustomDataGrid ItemsSource="{Binding MyItems}" SelectedItem="{Binding MySelectedItem,Mode=TwoWay}" x:Name="dataGrid">
    <i:Interaction.Triggers>
            <i:EventTrigger EventName="SelectionChanged">
                    <i:InvokeCommandAction Command="{Binding CommandName}" CommandParameter="{Binding ElementName=MainTabControl,Mode=OneWay}"/>
            </i:EventTrigger>
    </i:Interaction.Triggers>

EDIT:
My CustomDataGrid is driven from standard DataGrid and add an Event to it. it overrides two event: OnLoadingRow and OnUnLoadingRow.

Note that a simple CommandParameter e.g. a simple string was sent fine.

And MainTabControl is:

<sdk:TabControl Name="MainTabControl"> ...

What is the problem?

  • 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-17T00:46:13+00:00Added an answer on May 17, 2026 at 12:46 am

    OK, I have built a complete mockup of your situation and provided all code below. Everything is bare-bones, so everyone please ease up on the number of bad practices I put in it 🙂

    The bad new is, that my derived class works exactly the same as the normal DataGrid! When the command breakpoint is hit with the derived grid the parameter is exactly the same TabControl type.

    To take this further I would need to see what else you may be doing (in addition what you have already mentioned). Feel free to contact me through my website if you do not want to make your code public.

    View:

    <UserControl xmlns:my="clr-namespace:SilverlightApplication4"  xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" 
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
        xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" 
        x:Class="SilverlightApplication4.Page"
        mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="400">
    
        <Grid x:Name="LayoutRoot" Background="White" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
            <Grid.RowDefinitions>
                <RowDefinition Height="59*" />
                <RowDefinition Height="241*" />
            </Grid.RowDefinitions>
            <sdk:TabControl x:Name="MainTabControl">
                <sdk:TabItem Header="Tab1">Tab 1 content</sdk:TabItem>
                <sdk:TabItem Header="Tab2">Tab 2 content</sdk:TabItem>
                <sdk:TabItem Header="Tab3">Tab 3 content</sdk:TabItem>
            </sdk:TabControl>
            <!--data:DataGrid Grid.Row="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" AutoGenerateColumns="True" ItemsSource="{Binding MyItems}" SelectedItem="{Binding MySelectedItem, Mode=TwoWay}" x:Name="dataGrid" >
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="SelectionChanged">
                        <i:InvokeCommandAction Command="{Binding CommandName}" CommandParameter="{Binding ElementName=MainTabControl,Mode=OneWay}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </data:DataGrid-->
            <my:CustomDataGrid Grid.Row="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" AutoGenerateColumns="True" ItemsSource="{Binding MyItems}" SelectedItem="{Binding MySelectedItem, Mode=TwoWay}" x:Name="dataGrid2" >
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="SelectionChanged">
                        <i:InvokeCommandAction Command="{Binding CommandName}" CommandParameter="{Binding ElementName=MainTabControl,Mode=OneWay}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </my:CustomDataGrid>
        </Grid>
    </UserControl>
    

    Code-behind:

    using System.Windows.Controls;
    
    namespace SilverlightApplication4
    {
        public partial class Page : UserControl
        {
            public Page()
            {
                InitializeComponent();
                this.DataContext = new ViewModel();
            }
        }
    }
    

    ViewModel:

    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.Windows.Controls;
    using System.Windows.Input;
    using Microsoft.Practices.Prism.Commands;
    
    namespace SilverlightApplication4
    {
        public class ViewModel : INotifyPropertyChanged
        {
            public event PropertyChangedEventHandler PropertyChanged;
    
            public ICommand CommandName { get; set; }
            public ObservableCollection<Item> MyItems { get; set; }
    
            public Item MySelectedItem { get; set; }
    
            public ViewModel()
            {
                MyItems = new ObservableCollection<Item>();
                MyItems.Add(new Item() { FirstName = "Joe", LastName = "Blogs" });
                MyItems.Add(new Item() { FirstName = "Another", LastName = "One" });
                MyItems.Add(new Item() { FirstName = "Jane", LastName = "Blogs" });
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("MyItems"));
                }
                CommandName = new DelegateCommand<TabControl>(OnCommandAction);
            }
    
            public void OnCommandAction(TabControl param)
            {
                // Breakpoint here
            }
    
        }
    
        public class Item
        {
            public string FirstName { get; set; }
            public string LastName { get; set; }
        }
    }
    

    Custom datagrid:

    using System.Windows.Controls;
    
    namespace SilverlightApplication4
    {
        public class CustomDataGrid : DataGrid
        {
            protected override void OnLoadingRow(DataGridRowEventArgs e)
            {
                base.OnLoadingRow(e);
            }
    
            protected override void OnUnloadingRow(DataGridRowEventArgs e)
            {
                base.OnUnloadingRow(e);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.