How to pass UserControl with CommandParameter?

I have a DelegateCommand and I want to pass the UserControl using the command.

#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

Team in xaml

<Button Name="btnStockGroups" Command="{Binding OpenViewCommand}" CommandParameter="JIMS.View.Stock.StockGroups">stock group</Button>
+3
source share
1 answer

If you give your UserControl x: Name (for example, "MyView"), you can do something like this:

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

All Articles