6

我使用了 DelegateCommand,我想通过命令传递 UserControl。

#region OpenViewCommand
private DelegateCommand<UserControl> _openViewCommand;
public ICommand OpenViewCommand
{
    get
    {
        if (_openViewCommand == null)
            _openViewCommand = new DelegateCommand<UserControl>(new Action<UserControl>(OpenView));
        return _openViewCommand;
    }
}

public void OpenView(UserControl ViewName)
{
    UserControl ctrl = (UserControl)ViewName;
    JIMS.Controls.Message.Show(ViewName.ToString());
}
#endregion

XAML 中的命令

<Button Name="btnStockGroups" Command="{Binding OpenViewCommand}" CommandParameter="JIMS.View.Stock.StockGroups">stock group</Button>
4

1 回答 1

13

如果你给你的 UserControl 一个 x:Name(例如“MyView”),你应该能够做这样的事情:

<Button Name="btnStockGroups" 
        Command="{Binding OpenViewCommand}" 
        CommandParameter="{Binding ElementName=MyView}">
于 2012-05-03T20:22:53.340 回答