3

here is my Problem, I want to pass the integer 1 when this canvas is pressed. Every time I click the canvas, I get a An unhandled exception of type 'System.InvalidCastException' occurred in GalaSoft.MvvmLight.dll. Now I could make my life easier and just do the RelayCommand to accept a String instead of int but for the sake of learning. How would i go about doing it this way,

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

2 Answers 2

4

You just found a limitation of the generic casting. I am sorry about this. I will try to find a better way to handle simple values in a further version (maybe with some reflection to check if the Parse method is present on the type) and opened a bug in my backlog. In the mean time, please use RelayCommand and do the parsing yourself.

Cheers, Laurent

1

You can pass datatypes other than string to the command using the following syntax:

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

Add the flowing namespace declaration for s:

xmlns:s="clr-namespace:System;assembly=mscorlib"
1
  • This works for int, but when I tried using <s:Boolean>false</s:Boolean> it fell over (it passed 1 or 0)
    – Damian
    Jan 29, 2011 at 22:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.