现在的位置: 首页 > 综合 > 正文

MVVM : MouseDoubleClick of Listbox

2013年04月21日 ⁄ 综合 ⁄ 共 1155字 ⁄ 字号 评论关闭

xaml:

添加引用xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"

添加控件

<ListBox Width="180"      HorizontalAlignment="Left"
                                        ScrollViewer.VerticalScrollBarVisibility="Auto"
                                        ItemsSource="{Binding Products}"
                                        DisplayMemberPath="Name"
                                        SelectedItem="{Binding SelectedProducts}">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="MouseDoubleClick">
                                        <i:InvokeCommandAction Command="{Binding AddProductCommand}"/>
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </ListBox>

C# :

添加命令

    private RelayCommand _addProductCommand;

    public ICommand AddProducCommand
    {
      get
      {
        if (this._addProductCommand == null)
        {
          this._addProductCommand = new RelayCommand(
            () => this.AddSelectedProduct(),
            () => true);
        }
        return this._addProductCommand;
      }
    }

public AddSelectedProduct()

{

.....

}

抱歉!评论已关闭.