locked
How to Bind EventArgs and Command Parrameter to Command Event? RRS feed

  • Question

  • How to bind EventArgs and Command Parameter both together to a Command Event.

    xmlns:cmd="http://www.galasoft.ch/mvvmlight"

    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"

    <i:Interaction.Triggers>

    <i:EventTrigger EventName="SelectionChanged"> <cmd:EventToCommand Command="{Binding SelectionChangedCommand}" PassEventArgsToCommand="True"

    CommandParameter="Parameter"/>

    </i:EventTrigger> </i:Interaction.Triggers>

    private RelayCommand<object> _selectionChanged;
            public RelayCommand<object> SelectionChanged
            {
                get
                {
                    return _selectionChanged
                      ?? (_selectionChanged = new RelayCommand<object>(
                        async (_userTypeString) =>
                        {
                        });
                }
            }

    This is my code. In my View Model on command action, I am getting only the Command Parameter and not the Event Args. How to get both of them together ?

    Wednesday, July 24, 2019 10:29 AM

All replies

  • How to bind EventArgs and Command Parameter both together to a Command Event.

    xmlns:cmd="http://www.galasoft.ch/mvvmlight"

    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"

    <i:Interaction.Triggers>

    <i:EventTrigger EventName="SelectionChanged"> <cmd:EventToCommand Command="{Binding SelectionChangedCommand}" PassEventArgsToCommand="True"

    CommandParameter="Parameter"/>

    </i:EventTrigger> </i:Interaction.Triggers>

    private RelayCommand<object> _selectionChanged;
            public RelayCommand<object> SelectionChanged
            {
                get
                {
                    return _selectionChanged
                      ?? (_selectionChanged = new RelayCommand<object>(
                        async (_userTypeString) =>
                        {
                        });
                }
            }

    This is my code. In my View Model on command action, I am getting only the Command Parameter and not the Event Args. How to get both of them together ?


    Hi   UxyzTyr,
     
    In the MVVM-Light framework, its implementation of EventToCommand includes a PassEventArgsToCommand option to  pass event arguments as command parameter.

    >>This is my code. In my View Model on command action, I am getting only the Command Parameter and not the Event Args. How to get both of them together ?

    Unfortunately, I can't find a way to implement your ideas currently.

    I suggest you can go to the mvvmlight  support center for getting more information about EventToCommand.



    Best regards

    Yong Lu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, July 25, 2019 3:11 AM