<MenuItem Header="{Binding Hello, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type v:ProjectElementView}}}" />
v:ProjectElementViewはusercontrolのタイプです。usercontrolコードビハインド内のプロパティへのこの相対ソースバインディングが失敗しているのはなぜですか?
また、私はusercontrolに名前を付けて、ElementNameバインディングを使用してみました。
--Edit--
UserControl.xaml
<UserControl>
<Grid>
<TabControl>
<TabControl.ContextMenu>
<ContextMenu>
<MenuItem Header="{Binding Path=Hello, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type v:ProjectElementView}}}" />
</ContextMenu>
</TabControl.ContextMenu>
</Grid>
UserControl.xaml.cs
public partial class ProjectElementView : UserControl
{
private string _hello = "hello";
public string Hello
{
get { return _hello; }
set { _hello = value; }
}
}
ために、このリンクをチェックしてください。また、Visual Studioの出力ウィンドウにはバインドエラーがあります。あなたはそのテキストを提供できますか? –