Kishore Kumar
Kishore Kumar

Reputation: 12864

How to pass a UserControl with CommandParameter?

I have using a DelegateCommand and i want to pass the UserControl with 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

Command in XAML

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

Upvotes: 7

Views: 7946

Answers (1)

RobSiklos
RobSiklos

Reputation: 8849

If you give your UserControl an x:Name (e.g. "MyView"), you should be able to do something like this:

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

Upvotes: 13

Related Questions