contextmenu の wpf アプリケーションで使用したい単純なポップアップ コントロールがありますが、その isOpen プロパティは常に false を表示し、ポップアップは表示されません。コードだけでなくxamlでも変更しようとしましたが、すべて無駄でした。この予期しない動作が発生する理由を誰か教えてもらえますか?
<Grid>
<StackPanel>
<Popup x:Name="contextMenu" IsOpen="True" StaysOpen="False">
<Grid>
<Border BorderBrush="Black"
BorderThickness="2"
CornerRadius="3"
Background="AliceBlue">
<ListBox Name="ContextMenuList"
HorizontalAlignment="Stretch"
SelectionChanged="ContextMenuListSelectionChanged" />
ItemsSource="{Binding Path=ContextMenuListBinding}"
SelectedItem="{Binding Path=ContextMenuListBinding,
Mode=OneWay}"
</Border>
</Grid>
</Popup>
</StackPanel>
</Grid>
public void PositionContextMenu()
{
contextMenu.PlacementRectangle = new Rect(700, 250, 40, 30);
contextMenu.Placement = PlacementMode.Absolute;
contextMenu.IsOpen = true;
}
コードをデバッグすると、contextmenu.Isopen は常にその値を false として表示します。
関数の呼び出しは、MouseLeftbuttonDown イベント内で行われます:-
void MapMouseLeftButtonDownCommand(MouseEventArgs e)
{
var mycontextmenu = new MyContextMenu();
mycontextmenu.PositionContextMenu();
}
MyContextMenu は、ポップアップを含むコントロールです。