Casting in MVVM Light CommandParameterValue

here is my problem, I want to pass the integer 1 when I click this canvas. Every time I click on the canvas, I get an unhandled exception like "System.InvalidCastException" that occurred in GalaSoft.MvvmLight.dll. Now I could make my life easier and just make RelayCommand accept String instead of int, but for the sake of learning. How will I do it this way

    <i:Interaction.Triggers>
   <i:EventTrigger EventName="MouseLeftButtonDown">
         <cmd:EventToCommand Command="{Binding ButtonPress}"
                 CommandParameterValue="1"
              </i:EventTrigger>
    </i:Interaction.Triggers>
+3
source share
2 answers

. . (, , , Parse ) . , , RelayCommand .

Cheers, Laurent

+4

, , , :

<i:EventTrigger EventName="MouseLeftButtonDown">
    <cmd:EventToCommand Command="{Binding ButtonPress}">
        <cmd:EventToCommand.CommandParameterValue>
            <s:Int32>1</s:Int32>
        </cmd:EventToCommand.CommandParameterValue>
    </cmd:EventToCommand>
</i:EventTrigger>

s:

xmlns:s="clr-namespace:System;assembly=mscorlib"
+1

Source: https://habr.com/ru/post/1739082/


All Articles