views:

163

answers:

1

Hello,

I'm just starting with MVVM light, but so far it allowed me to solve some of my issues. Infortunately I'm struggling with relatively sime issues in Silverlight.

Let's assume the following button with EventToCommand:

<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseEnter">
<GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding UpdateAccountsCommand, Mode=OneWay}" CommandParameter="{Binding SelectedIndex, ElementName=lstLedgers}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>

How to assign this code to SelectedIndexChanged event?

Futher issue - how to assign a command in C# code? The problem is as follows: I'm developing Windows Phone 7 app. Application Bar needs to be initiated in C# (as far as I know there is no xaml code for application bar at this stage). As a result I have no idea how to bind a command to a application bat button in from c#, now xaml.

Thanks in advance your your help.

A: 

How to assign this code to SelectedIndexChanged event

The event name is in the trigger's initial xaml line. The EventName is what triggers something to happen. You'll need to make sure that you have this trigger on an object with a SelectedIndexChanged event. Button doesn't have that event.

...
<i:EventTrigger EventName="SelectedIndexChanged"> 
...

If you are breaking mvvm for the application bar, I don't know why you'd want to create a trigger. You might as well go the direct route by accessing the events you want directly. You can do it, don't get me wrong... just this code is a lot cleaner:

ApplicationBarButton.Click += new RoutedEventHandler(OnApplicationBarButton_Click);
Jeremiah
Given the application bar - the problem is that Click rises an event. I don't know how can I bind a method from view model, because view does not "see" view model layer at all!In xaml I could to this via binding, but in c# I'm lost.
Hikari
The answer was so close :)http://blog.galasoft.ch/archive/2010/04/09/using-commands-with-applicationbarmenuitem-and-applicationbarbutton-in-windows-phone-7.aspx
Hikari