我使用了 DelegateCommand,我想通过 Command 传递 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>
最佳答案
如果你给你的 UserControl 一个 x:Name(例如“MyView”),你应该能够做这样的事情:
<Button Name="btnStockGroups"
Command="{Binding OpenViewCommand}"
CommandParameter="{Binding ElementName=MyView}">
关于c# - 如何使用 CommandParameter 传递 UserControl?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10438564/