如何扩展 ComboBox 以支持命令 (MVVM)?
正如主题所述,我需要扩展标准 Silverlight ComboBox 的功能以支持命令。由于我遵循 MVVM,因此我需要 ComboBox 将 SelectionChanged 事件传达给我的 ViewModel。
执行此操作的代码是什么样的?我希望能够将 Command 属性放在 ComboBox XAML 控件上。
使用(WCF RIA、MVVM、VB.NET)..
所有技巧均已应用!
As topic says, I need to extend the features of a standard Silverlight ComboBox to also support Commanding. Since I follow MVVM I need my ComboBox to communicate the SelectionChanged event to my ViewModel.
What would the code look like for doing this? I want to be able to put the Command attribute on my ComboBox XAML control.
Using (WCF RIA, MVVM, VB.NET)..
All tips appricated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将 Combobox 的属性 SelectedIndex 或 SelectedItem 绑定到 ViewModel。所以你不需要任何命令。
示例(绑定到 SelectedIndex):
XAML
C#
示例(绑定到 SelectedItem):
XAML
C#
You can bind the property SelectedIndex or SelectedItem of the Combobox to your ViewModel. So you don´t need any Commands.
Example (Binding to SelectedIndex):
XAML
C#
Example (Binding to SelectedItem):
XAML
C#
创建一个公开
ICommand Command
和对象CommandParameter
的行为。在行为中连接到 AssociatedObject 的 SelectionChanged 事件。然后,您可以将该命令绑定到您的行为并模拟 SelectionChanged 事件的命令。Create a behavior that exposes an
ICommand Command
and aobject CommandParameter
. In the behavior wire up to the SelectionChanged event of your AssociatedObject. Then you can bind the command to your behavior and simulate a command for the SelectionChanged event.