左クリックするUserControlとButton開く内部があります。の親をアイテムのコマンドにパラメーターとしてContextMenu渡して、そのウィンドウを閉じようとしていますが、役に立ちません。とですべてを試しましたが、パラメーターは常に null です。親ウィンドウの一部ではないことは承知しています。私は現在、このアプローチに固執していますが、機能していません。UserControlWindowContextMenuRelativeSourcePlacementTargetContextMenuVisualTree
<Grid x:Name="LayoutRoot">
<Button
HorizontalAlignment="Left"
Margin="0"
Style="{DynamicResource ButtonStyle1}"
VerticalAlignment="Top"
Width="120"
Height="25"
Content="Dashboard Menu"
TextElement.FontWeight="Bold"
Foreground="AliceBlue"
>
<!--Tag="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={ x:Type Window}}}"-->
<Button.ContextMenu>
<ContextMenu DataContext="{Binding PlacementTarget, RelativeSource={RelativeSource Self}}" >
<MenuItem Header="Open Log Viewer" Command="{StaticResource openLogViewer}" />
<Separator />
<MenuItem Header="Exit" Command="{StaticResource exit}" CommandParameter="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource AncestorType=Window}}"/>
</ContextMenu>
</Button.ContextMenu>
</Button>
</Grid>
Command は、 で定義されている参照コマンドですUserControl.Resources:
<my:CommandReference x:Key="exit" Command="{Binding Exit}" />
実行部分がトリガーされますが、パラメーターは常にnullです。CommandParameterだから、私の質問は、の時点で親ウィンドウをバインドする正しい方法は何ですかMenuItem. このことはほぼ2日間私を悩ませているので、助けていただければ幸いです。