Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 843
Kishore Kumar Avatar asked May 03 '12 20:05

Kishore Kumar


1 Answers

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}">
like image 104
RobSiklos Avatar answered Sep 28 '22 19:09

RobSiklos