Hi, I have a WPF application which has a main window composed from several custom UserControls placed in AvalonDock containers.
I want some of the UserControls' functionality to be accessible from a toolbar and menubar in the main window. I have a command defined as this in the control like this:
public ICommand UnfoldAllCommand
{
get
{
if (this.unfoldAllCommand == null)
{
this.unfoldAllCommand = new RelayCommand(param => this.UnfoldAll());
}
return unfoldAllCommand;
}
}
Now I have this UserControl defined in main window XAML under name "editor"
<local:Editor x:Name="editor" />
This control is also made public via Edtor property of the main window (the window is its own DataContext).
public Editor Editor { get { return this.editor; } }
The menubar is located in the main window XAML. This definition definition of one MenuItem which triggers the UserControl's UnfoldAll command works perfectly.
<MenuItem Header="Unfold All" Command="{Binding UnfoldAllCommand, ElementName=editor}" InputGestureText="Ctrl+U" />
However, this definition is arguably prettier, but it doesn't work (the MenuItem is clickable, but won't fire the UnfoldAll method):
<MenuItem Header="Unfold All" Command="{Binding Editor.UnfoldAllCommand}" InputGestureText="Ctrl+U" />
Why?