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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:50:20+00:00 2026-05-24T09:50:20+00:00

I’m trying to convert an event to a command on a devexpress wpf grid

  • 0

I’m trying to convert an event to a command on a devexpress wpf grid context menu item which is derived from FrameworkContentElement instead of FrameworkElement. This causes a runtime error :

{“Cannot attach type \”EventToCommand\” to type \”BarButtonItem\”. Instances of type \”EventToCommand\” can only be attached to objects of type \”FrameworkElement\”.”}

Is there any workaround?

<dxg:TableView.RowCellMenuCustomizations>
    <dxb:BarButtonItem Name="deleteRowItem" Content="Delete" >
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="ItemClick">
                <cmd:EventToCommand Command="{Binding FooChangeCommand}"
                PassEventArgsToCommand="True" />
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </dxb:BarButtonItem>

    <!--ItemClick="deleteRowItem_ItemClick"/>-->
</dxg:TableView.RowCellMenuCustomizations>

Unfortunately devexpress have run into problems changing the base class to FrameworkElement having intended to make that change…

  • 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-24T09:50:22+00:00Added an answer on May 24, 2026 at 9:50 am

    The FrameworkConentElement is a class that is only available in WPF and not in Silverlight. As MVVM Light is intended to provide a common functionality for all WPF dialects (WPF 3.5, WPF 4, Silverlight 3, Silverlight 4, Sivlverlight 5, WP 7, WP 7.1) it cannot include an implementation that only works in one of the frameworks.

    For a discussion about the differences between FrameworkElement and FrameworkContentElement see here.

    However, you can just easily implement your own EventToCommand class supporting ContentElement (from which FrameworkContentElement inherits). The class was copied from BL0015 of the MVVM Light source code and modified:

    using System;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Interactivity;
    
    namespace GalaSoft.MvvmLight.Command
    {
        /// <summary>
        /// This <see cref="System.Windows.Interactivity.TriggerAction" /> can be
        /// used to bind any event on any FrameworkElement to an <see cref="ICommand" />.
        /// Typically, this element is used in XAML to connect the attached element
        /// to a command located in a ViewModel. This trigger can only be attached
        /// to a FrameworkElement or a class deriving from FrameworkElement.
        /// <para>To access the EventArgs of the fired event, use a RelayCommand&lt;EventArgs&gt;
        /// and leave the CommandParameter and CommandParameterValue empty!</para>
        /// </summary>
        ////[ClassInfo(typeof(EventToCommand),
        ////  VersionString = "3.0.0.0",
        ////  DateString = "201003041420",
        ////  Description = "A Trigger used to bind any event to an ICommand.",
        ////  UrlContacts = "http://stackoverflow.com/q/6955785/266919",
        ////  Email = "")]
        public partial class EventToCommandWpf : TriggerAction<DependencyObject>
        {
            /// <summary>
            /// Gets or sets a value indicating whether the EventArgs passed to the
            /// event handler will be forwarded to the ICommand's Execute method
            /// when the event is fired (if the bound ICommand accepts an argument
            /// of type EventArgs).
            /// <para>For example, use a RelayCommand&lt;MouseEventArgs&gt; to get
            /// the arguments of a MouseMove event.</para>
            /// </summary>
            public bool PassEventArgsToCommand
            {
                get;
                set;
            }
    
            /// <summary>
            /// Provides a simple way to invoke this trigger programatically
            /// without any EventArgs.
            /// </summary>
            public void Invoke()
            {
                Invoke(null);
            }
    
            /// <summary>
            /// Executes the trigger.
            /// <para>To access the EventArgs of the fired event, use a RelayCommand&lt;EventArgs&gt;
            /// and leave the CommandParameter and CommandParameterValue empty!</para>
            /// </summary>
            /// <param name="parameter">The EventArgs of the fired event.</param>
            protected override void Invoke(object parameter)
            {
                if (AssociatedElementIsDisabled())
                {
                    return;
                }
    
                var command = GetCommand();
                var commandParameter = CommandParameterValue;
    
                if (commandParameter == null
                     && PassEventArgsToCommand)
                {
                    commandParameter = parameter;
                }
    
                if (command != null
                     && command.CanExecute(commandParameter))
                {
                    command.Execute(commandParameter);
                }
            }
    
            private static void OnCommandChanged(
                 EventToCommandWpf element,
                 DependencyPropertyChangedEventArgs e)
            {
                if (element == null)
                {
                    return;
                }
    
                if (e.OldValue != null)
                {
                    ((ICommand)e.OldValue).CanExecuteChanged -= element.OnCommandCanExecuteChanged;
                }
    
                var command = (ICommand)e.NewValue;
    
                if (command != null)
                {
                    command.CanExecuteChanged += element.OnCommandCanExecuteChanged;
                }
    
                element.EnableDisableElement();
            }
    
            private bool AssociatedElementIsDisabled()
            {
                var element = GetAssociatedObject();
                return AssociatedObject == null
                     || (element != null
                         && !element.IsEnabled);
            }
    
            private void EnableDisableElement()
            {
                var element = GetAssociatedObject();
    
                if (element == null)
                {
                    return;
                }
    
                var command = this.GetCommand();
    
                if (this.MustToggleIsEnabledValue
                     && command != null)
                {
                    SetIsEnabled(element, command.CanExecute(this.CommandParameterValue));  
                }
            }
    
            private void OnCommandCanExecuteChanged(object sender, EventArgs e)
            {
                EnableDisableElement();
            }
    
            /// <summary>
            /// Identifies the <see cref="CommandParameter" /> dependency property
            /// </summary>
            public static readonly DependencyProperty CommandParameterProperty = DependencyProperty.Register(
                 "CommandParameter",
                 typeof(object),
                 typeof(EventToCommandWpf),
                 new PropertyMetadata(
                      null,
                      (s, e) => {
                          var sender = s as EventToCommandWpf;
                          if (sender == null)
                          {
                              return;
                          }
    
                          if (sender.AssociatedObject == null)
                          {
                              return;
                          }
    
                          sender.EnableDisableElement();
                      }));
    
            /// <summary>
            /// Identifies the <see cref="Command" /> dependency property
            /// </summary>
            public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
                 "Command",
                 typeof(ICommand),
                 typeof(EventToCommandWpf),
                 new PropertyMetadata(
                      null,
                      (s, e) => OnCommandChanged(s as EventToCommandWpf, e)));
    
            /// <summary>
            /// Identifies the <see cref="MustToggleIsEnabled" /> dependency property
            /// </summary>
            public static readonly DependencyProperty MustToggleIsEnabledProperty = DependencyProperty.Register(
                 "MustToggleIsEnabled",
                 typeof(bool),
                 typeof(EventToCommandWpf),
                 new PropertyMetadata(
                      false,
                      (s, e) => {
                          var sender = s as EventToCommandWpf;
                          if (sender == null)
                          {
                              return;
                          }
    
                          if (sender.AssociatedObject == null)
                          {
                              return;
                          }
    
                          sender.EnableDisableElement();
                      }));
    
            private object _commandParameterValue;
    
            private bool? _mustToggleValue;
    
            /// <summary>
            /// Gets or sets the ICommand that this trigger is bound to. This
            /// is a DependencyProperty.
            /// </summary>
            public ICommand Command
            {
                get
                {
                    return (ICommand)GetValue(CommandProperty);
                }
    
                set
                {
                    SetValue(CommandProperty, value);
                }
            }
    
            /// <summary>
            /// Gets or sets an object that will be passed to the <see cref="Command" />
            /// attached to this trigger. This is a DependencyProperty.
            /// </summary>
            public object CommandParameter
            {
                get
                {
                    return this.GetValue(CommandParameterProperty);
                }
    
                set
                {
                    SetValue(CommandParameterProperty, value);
                }
            }
    
            /// <summary>
            /// Gets or sets an object that will be passed to the <see cref="Command" />
            /// attached to this trigger. This property is here for compatibility
            /// with the Silverlight version. This is NOT a DependencyProperty.
            /// For databinding, use the <see cref="CommandParameter" /> property.
            /// </summary>
            public object CommandParameterValue
            {
                get
                {
                    return this._commandParameterValue ?? this.CommandParameter;
                }
    
                set
                {
                    _commandParameterValue = value;
                    EnableDisableElement();
                }
            }
    
            /// <summary>
            /// Gets or sets a value indicating whether the attached element must be
            /// disabled when the <see cref="Command" /> property's CanExecuteChanged
            /// event fires. If this property is true, and the command's CanExecute 
            /// method returns false, the element will be disabled. If this property
            /// is false, the element will not be disabled when the command's
            /// CanExecute method changes. This is a DependencyProperty.
            /// </summary>
            public bool MustToggleIsEnabled
            {
                get
                {
                    return (bool)this.GetValue(MustToggleIsEnabledProperty);
                }
    
                set
                {
                    SetValue(MustToggleIsEnabledProperty, value);
                }
            }
    
            /// <summary>
            /// Gets or sets a value indicating whether the attached element must be
            /// disabled when the <see cref="Command" /> property's CanExecuteChanged
            /// event fires. If this property is true, and the command's CanExecute 
            /// method returns false, the element will be disabled. This property is here for
            /// compatibility with the Silverlight version. This is NOT a DependencyProperty.
            /// For databinding, use the <see cref="MustToggleIsEnabled" /> property.
            /// </summary>
            public bool MustToggleIsEnabledValue
            {
                get
                {
                    return this._mustToggleValue == null
                                  ? this.MustToggleIsEnabled
                                  : this._mustToggleValue.Value;
                }
    
                set
                {
                    _mustToggleValue = value;
                    EnableDisableElement();
                }
            }
    
            /// <summary>
            /// Called when this trigger is attached to a DependencyObject.
            /// </summary>
            protected override void OnAttached()
            {
                base.OnAttached();
                EnableDisableElement();
            }
    
            /// <summary>
            /// This method is here for compatibility
            /// with the Silverlight version.
            /// </summary>
            /// <returns>The object to which this trigger
            /// is attached casted as a FrameworkElement.</returns>
            private IInputElement GetAssociatedObject()
            {
                return AssociatedObject as IInputElement;
            }
    
            private void SetIsEnabled(IInputElement element, bool value)
            {
                if (element is UIElement)
                {
                    ((UIElement)element).IsEnabled = value;
                }
                else if (element is ContentElement)
                {
                    ((ContentElement)element).IsEnabled = value;
                }
                else
                {
                    throw new InvalidOperationException("Cannot set IsEnabled. Element is neither ContentElemen, nor UIElement.");
                }
            }
    
            /// <summary>
            /// This method is here for compatibility
            /// with the Silverlight version.
            /// </summary>
            /// <returns>The command that must be executed when
            /// this trigger is invoked.</returns>
            private ICommand GetCommand()
            {
                return Command;
            }
        }
    }
    

    To inlcude it into your code you have to define a xml namespace pointing to the correct dll and then use it just like the normal EventToCommand class.

    NOTE: This class does not work in Silverlight!

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string

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.