This question is related to the question at: http://ko.infragistics.com/community/forums/t/86353.aspx
I am also trying to use the MenuTool in MVVM. Trying to do what the original poster likes to do, I looked through all the suggested threads, however, I was not able to get the MenuTool to work.
Here's the XAML:
<igRibbon:MenuTool Caption="Status" ItemsSource="{Binding MenuItems}"> <igRibbon:MenuTool.ItemContainerStyle> <Style TargetType="{x:Type igRibbon:ToolMenuItem}"> <Setter Property="Command" Value="{Binding SetStatusCommand}"/> <Setter Property="CommandParameter" Value="{Binding}"/> </Style> </igRibbon:MenuTool.ItemContainerStyle></igRibbon:MenuTool>
Here's the VM:
public class ViewModel:ViewModelBase
{
public ViewModel()
MenuItems = new ObservableCollection<string> { "Active", "InActive", "Test" };
SetStatusCommand = new DelegateCommand<string>(SetStatus);
}
public DelegateCommand<string> SetStatusCommand { get; set; }
private ObservableCollection<string> _MenuItems;public ObservableCollection<string> MenuItems{ get { return _MenuItems; } set { if (value != _MenuItems) { _MenuItems = value; RaisePropertyChanged(); } }}
private void SetStatus(string status){ var parameter = status;}
When I click on the item from the menu drop-down, the SetStatusCommand was not fired.
What did I do wrong?
If you can prepare a simple sample showing how to use the MenuTool in MVVM will be a great help.
Thank you very much.
Hi yingwu,
The binding for that command isn't pointing in the right spot. The DataContext for the menu item is going to be the string inside your MenuItems collection. The string data type doesn't have a property called SetStatusCommand so the binding fails. It needs to be changed to point to the ViewModel class. You do this by changing it to:
<Setter Property="Command" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type igRibbon:MenuTool}}, Path=DataContext.SetStatusCommand}"/>
Thank you Rob, it works now.