0
私はすでにこの問題を解決していますが、解決策は私の意見では直観ではありません。これにXAMLここWPF ContextMenu.IsOpenにバインドするコンテキストメニューが最初の呼び出し時に画面の左上隅に点滅する
public class VMMain : INotifyPropertyChanged
{
private bool shouldShow;
public event PropertyChangedEventHandler PropertyChanged;
public bool ShouldShow
{
get { return shouldShow; }
set
{
shouldShow = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ShouldShow)));
}
}
}
とされています:あなたが正しい、この中で
<Window x:Class="TestContextMenuBug.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:TestContextMenuBug"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid Background="Transparent">
<Grid.ContextMenu>
<ContextMenu IsOpen="{Binding ShouldShow}">
<MenuItem Header="Menu Item" />
</ContextMenu>
</Grid.ContextMenu>
</Grid>
</Window>
クリック以下
がこのビューでコンテキストメニューに結合する性質を持つShouldShow
ビューモデルですウィンドウを初めて表示すると、コンテキストメニューが画面の左上隅に短く点滅します。以降のすべてのクリックは正常に動作します。