开发者

How to assign RelayCommand to Click or SelectedIndexChanges events?

开发者 https://www.devze.com 2022-12-27 20:09 出处:网络
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.

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 th开发者_JS百科is 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.


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消