How to pass a UserControl with CommandParameter?
binding, c#, view, wpf, xaml
Solution
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}">
Problem
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> ```