Search code examples
c#wpfxamlicommand

How specific CommandParameter in xaml to know type of object


I use iCommand in my project. I've got a window with buttons. Every button contain Image with category of clothes and every category has it own class. After click on button I need to know type of category in parameter. Is there any solution for my problem?

<i:Interaction.Triggers>
<i:EventTrigger EventName="HandCursorClick">
<i:InvokeCommandAction Command="{Binding MyCommand}" CommandParameter="{Binding ????}"/>
</i:EventTrigger>
</i:Interaction.Triggers>

I can bind Image, but it isn't giving me proper answer about type of object which represents that image...

In BehindCode I've got:

public ICommand MyCommand
        {
           get { return _myCommand ?? (_myCommand = new DelegateCommand<object>(CategoryExecuted)); }
        }

public void CategoryExecuted(object parameter)
        {
           Shoes s = parameter as Shoes;
           if(s!=null)
           {
           ....
           }
        }

Solution

  • if you have lat's say Category_1 property in your view model you can bind to it in the command parameter in the Button of category1 to usethe binding
    the key is to have the property in your view model

    <i:InvokeCommandAction Command="{Binding MyCommand}" CommandParameter="{Binding Category_1}"/>