我有一个简单的场景,我在 a 中隐藏和显示一个信号MenuItem
,ContextMenu
如下所示:
xml:
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Window.ContextMenu>
<ContextMenu Name="mainMnu">
<MenuItem Name="mnu" Header="Testing"/>
</ContextMenu>
</Window.ContextMenu>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Button HorizontalAlignment="Left" Margin="52,131,0,108" Name="Button1"
Width="75">Button</Button>
</Grid>
</Window>
后面的代码:
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
If mnu.Visibility = Windows.Visibility.Visible Then
mnu.Visibility = Windows.Visibility.Collapsed
mainMnu.Visibility = Windows.Visibility.Collapsed
Else
mnu.Visibility = Windows.Visibility.Visible
mainMnu.Visibility = Windows.Visibility.Visible
End If
End Sub
问题是每隔一次我按Button
没有MenuItem
显示。右键单击仅显示一个小的空矩形。(就像有一个可见的菜单,但不是一个可见的MenuItem
)。它以某种方式循环工作......前2次点击:问题,接下来2次点击ok,等等......
有任何想法吗?