如何将 RelayCommand 分配给 Click 或 SelectedIndexChanges 事件?
我刚刚开始使用 MVVM light,但到目前为止它让我解决了一些问题。不幸的是,我在 Silverlight 中遇到了相对简单的问题。
让我们假设以下带有 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>
如何将此代码分配给 SelectedIndexChanged 事件?
进一步的问题 - 如何在 C# 代码中分配命令? 问题如下:我正在开发 Windows Phone 7 应用程序。应用程序栏需要在C#中启动(据我所知,现阶段没有应用程序栏的xaml代码)。因此,我不知道如何将命令绑定到 c#(现在是 xaml)中的应用程序 bat 按钮。
预先感谢您的帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事件名称位于触发器的初始 xaml 行中。
EventName
是触发事件发生的原因。您需要确保在具有 SelectedIndexChanged 事件的对象上有此触发器。按钮没有该事件。如果您要破坏应用程序栏的 mvvm,我不知道您为什么要创建触发器。您不妨走直接路线,直接访问您想要的事件。你可以做到,不要误会我的意思......只是这段代码更干净:
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.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: