【问题标题】:Getting a handle on the listboxitem in RelayCommand method在 RelayCommand 方法中获取 listboxitem 的句柄
【发布时间】:2012-03-09 18:59:50
【问题描述】:

这是为 WP7 准备的。 我在列表框项目模板中有一个按钮。在关联的 ViewModel 中,我有 RelayCommand,我已将其绑定到 Button 的 Click 事件(使用 MVVMLight EventToCommand)。我想要的只是在单击按钮时传入 ListBox 的 ListItem 。

有什么想法吗?

【问题讨论】:

    标签: windows-phone-7 mvvm-light


    【解决方案1】:

    在 xaml 中使用 CommandParameter="{Binding}" 会将您选择的 ListItem 传递给命令

    然后在视图模型中

    private RelayCommand<ListItem> _command;
    
    public RelayCommand<ListItem> Command
    {
        get
        {
            return _command ?? (_command = new RelayCommand(Method));
        }
    }
    
    public void Method(ListItem item)
    {
        ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-23
      • 2015-11-08
      • 1970-01-01
      相关资源
      最近更新 更多