C# 如何使用CommandParameter传递UserControl?

C# 如何使用CommandParameter传递UserControl?,c#,wpf,xaml,binding,view,C#,Wpf,Xaml,Binding,View,我已经使用了DelegateCommand,我想通过该命令传递UserControl #region OpenViewCommand private DelegateCommand<UserControl> _openViewCommand; public ICommand OpenViewCommand { get { if (_openViewCommand == null) _openViewCommand = new D

我已经使用了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
#区域打开视图命令
私有DelegateCommand openViewCommand;
公共ICommand openview命令
{
得到
{
如果(_openViewCommand==null)
_openViewCommand=新的DelegateCommand(新操作(OpenView));
返回openview命令;
}
}
public void OpenView(UserControl ViewName)
{
UserControl ctrl=(UserControl)ViewName;
JIMS.Controls.Message.Show(ViewName.ToString());
}
#端区
XAML中的命令

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

如果你给你的用户控件一个x:Name(例如“MyView”),你应该可以这样做:

<Button Name="btnStockGroups" 
        Command="{Binding OpenViewCommand}" 
        CommandParameter="{Binding ElementName=MyView}">


该元素不在窗口中。。它是一个UserControl文件在不命名元素的情况下,如何执行此操作?为什么需要访问ViewModel中的控件?一般的MVVM方法是将控件绑定到ViewModel,并从绑定到的属性中读取数据。OpenView命令是否旨在使特定类型的UserControl实例化并显示给用户?