Interactivity to a combobox: cannot add EventTrigger (WPF, VS2008) RRS feed

  • Question

  • Hi All,

    I am using WPF and VS2008.

    I am trying to add interactivity to a combobox, so that I can add a command to it. I basically want a command to fire when the selected object is changed:

    <Window x:Class="InteractivityTest.Window1"
     Title="Window1" Height="300" Width="300"
      <ComboBox Name="ProfileOptionsComboBox">
        <i:EventTrigger EventName="SelectionChanged">
           CommandParameter="{Binding SelectedItem, ElementName=ProfileOptionsComboBox, Mode=OneWay}" />

    However when I run this I get the following error:

    Cannot add content of type 'System.Windows.Interactivity.EventTrigger' to an object of type 'System.Windows.Interactivity.TriggerCollection'.  Error at object 'System.Windows.Interactivity.EventTrigger' in markup file 'InteractivityTest;component/window1.xaml' Line 16 Position 19.

    I have tried searching for examples of TriggerCollection but can find no XAML examples.

    Furthermore, my System.Windows.Interactivity does not provide any intellisense suggestion for TriggerCollection in XAML (but it is there in the code intellisense). - I don't actually think this is relevent to the problem though! :)

    Any ideas?



    • Edited by Iobetes Friday, May 21, 2010 3:08 PM not being able to write a coherent post
    Friday, May 21, 2010 1:13 PM

All replies

  • "Furthermore, my System.Windows.Interactivity"


    I suspect the end of that sentence has something to do with the problem, could you fill that in? :)

    Friday, May 21, 2010 1:46 PM
  • This may be little late for the person who made the post.. but It may be helpful for someone who is facing such kinda problem in v3.5. At least for me it worked.

    create a class like:

     public class CommonActions : TriggerAction<FrameworkElement>
            public static readonly DependencyProperty CommandProperty =
    DependencyProperty.Register("Command", typeof(string), typeof(FrameworkElement));

            public string Command
                get { return base.GetValue(CommandProperty) as string; }
                set { base.SetValue(CommandProperty, value); }

            public static readonly DependencyProperty CommandParameterProperty =
    DependencyProperty.Register("CommandParameter", typeof(string), typeof(FrameworkElement));

            public string CommandParameter
                get { return base.GetValue(CommandParameterProperty) as string; }
                set { base.SetValue(CommandParameterProperty, value); }
            protected override void Invoke(object param)
                if (Command != null)
                    object ctx =  AssociatedObject.DataContext;
                    if (ctx != null)
                        var cmd = ctx.GetType().GetProperty(Command).GetValue(ctx, null) as ICommand;
                        object o = AssociatedObject.GetType().GetProperty(CommandParameter).GetValue(AssociatedObject,null);
                        if (cmd != null && cmd.CanExecute(o))

    Add these namespaces in XAML:


    and use in the control like:

                                    <ei:EventTrigger EventName="SelectionChanged">
                                        <i:CommonActions Command="SetEditNameCommand" CommandParameter="SelectedIndex"/>

    • Edited by VibhorJain Monday, June 3, 2013 6:13 AM
    Monday, June 3, 2013 6:10 AM