Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 如何扩展组合框以支持命令(MVVM)?_Vb.net_Silverlight_Mvvm_Combobox_Command - Fatal编程技术网

Vb.net 如何扩展组合框以支持命令(MVVM)?

Vb.net 如何扩展组合框以支持命令(MVVM)?,vb.net,silverlight,mvvm,combobox,command,Vb.net,Silverlight,Mvvm,Combobox,Command,正如主题所说,我需要扩展标准Silverlight组合框的功能,以支持命令。因为我遵循MVVM,所以我需要我的组合框将SelectionChanged事件传递给我的ViewModel 这样做的代码是什么样子的?我希望能够将Command属性放在ComboBox XAML控件上 使用(WCF RIA、MVVM、VB.NET) 所有提示都收到了 创建一个公开ICommand命令和对象命令参数的行为。在关联对象的SelectionChanged事件之前的行为关联中。然后,您可以将命令绑定到您的行为,并

正如主题所说,我需要扩展标准Silverlight组合框的功能,以支持命令。因为我遵循MVVM,所以我需要我的组合框将SelectionChanged事件传递给我的ViewModel

这样做的代码是什么样子的?我希望能够将Command属性放在ComboBox XAML控件上

使用(WCF RIA、MVVM、VB.NET)


所有提示都收到了

创建一个公开
ICommand命令
对象命令参数
的行为。在关联对象的SelectionChanged事件之前的行为关联中。然后,您可以将命令绑定到您的行为,并模拟SelectionChanged事件的命令。

您可以将组合框的属性SelectedIndex或SelectedItem绑定到ViewModel。所以你不需要任何命令

示例(绑定到SelectedIndex):

XAML

示例(绑定到SelectedItem):

XAML


如果还需要访问当前选定的对象,则可以对SelectedItem属性执行完全相同的操作。如果出于某种原因,您决定命令另一个事件,如Focus,我会检查,查看EventToCommand行为部分。回答很好,我会继续尝试
<ComboBox SelectedIndex="{Binding SelectedIndex, Mode=TwoWay}"/>
public class ComboBoxViewModel
{
   private int _selectedIndex;
   public int SelectedIndex {
     get { return _selectedIndex; }
     set { 
       if (value != _selectedIndex) {
         _selectedIndex = value;
         // Perform any logic, when the SelectedIndex changes (aka. PropertyChanged-Notification)
       }
     } 
   }
}
<ComboBox SelectedItem="{Binding SelectedItem, Mode=TwoWay}"/>
public class ComboBoxViewModel
{
   private MyViewModel _selectedItem;
   public MyViewModel SelectedItem {
     get { return _selectedItem; }
     set { 
       if (value != _selectedItem) {
         _selectedItem= value;
         // Perform any logic, when the SelectedIndex changes ((aka. PropertyChanged-Notification)
       }
     } 
   }
}