TreeView に ContextMenu があります
UserControl (DataContext=ViewModel)
|
|
---- TreeView (ItemSource=MyItems)
|
|
----- Items (ItemSource=MyChildrenItems)
|
|
----- ContextMenu
ContextMenuItem の Command を ViewModel の RelayCommand にバインドしたいのですが、あらゆる種類の RelativeSource バインディングを試しましたが、何もうまくいかないようです...
RelativeSource バインディングはどのように構成すればよいですか?
<ContextMenu>
<MenuItem
Header="Bla"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=TreeView}, Path=DataContext.MyRelayCommand}" />
次のようなバインディングエラーが発生します
参照 'RelativeSource FindAncestor、AncestorType='System.Windows.Controls.TreeView'、AncestorLevel='1'' でバインディングのソースが見つかりません。BindingExpression:Path=DataContext.ExcludeSeasonCommand; DataItem=null; ターゲット要素は 'MenuItem' (Name='') です。ターゲット プロパティは 'Command' (タイプ 'ICommand') です。