Element binding params with Event Triggers

Oct 20, 2010 at 3:22 PM

I have a view, as follows:

<ComboBox x:Name="ViewSelection"  Style="{StaticResource ComboBoxStyle}" cal:Message.Attach="DataViewArbiter($eventArgs)">

<!-- some combobox items -->

 <Button x:Name="RefreshView" Width="50"  Height="54">
                    <i:EventTrigger EventName="Click">
                        <cal:ActionMessage MethodName="ActivateViewByName">
                            <cal:Parameter Value="{Binding ElementName=ViewSelection, Path=SelectedItem.Name}" />

Now, in my VM, my ActivateViewByName method gets called, however, I always get null for my param value.  Am I doing something wrong here?



Oct 20, 2010 at 4:20 PM
Edited Oct 20, 2010 at 4:29 PM

Hi RBisch,

I tried the code that you have but modified 

<cal:Parameter Value="{Binding ElementName=ViewSelection, Path=SelectedItem.Name}" /> 
<cal:Parameter Value="{Binding ElementName=ViewSelection, Path=SelectedItem}" />

and I am getting the correct values. I believe SelectedItem is passed as an object since you are defining them in the XAML as opposed to binding to a list, so there would be no "Name" property.

Also you can take advantage of some of the smart defaults from the message parser and change your code to the following


            <Button x:Name="RefreshView"


Oct 20, 2010 at 4:31 PM
Edited Oct 20, 2010 at 5:35 PM



You're right, I am not databinding my combobox[items], they are defined in XAML.


Note: I also believe the param type in the VM is critical.  I believe if your param type cannot be casted to by the type that CM sends in the message, you will get null, vs. typecast exception.  I am not sure about this though.

Thanks, I'll give that a try!