弹出菜单无法处理MenuItem
本文关键字:处理 MenuItem 菜单 | 更新日期: 2023-09-27 18:24:24
我必须在单击MenuItem时显示弹出菜单。我已经为此写了以下代码:
<ContextMenu>
<Border>
<MenuItem Name="ack" Header="ACK" HorizontalAlignment="Center" Command="{Binding AcknowledgeCommand}" Visibility="{Binding IsAcked, Converter={StaticResource showOnFalse}}" Click="MenuItem_Click_1"/>
</Border>
<Separator/>
<Border>
<MenuItem Header="Info" HorizontalAlignment="Center" Click="MenuItem_Click"/>
</Border>
<Separator/>
<Border>
<MenuItem Header="Goto" HorizontalAlignment="Center"/>
</Border>
<Popup Name="infoPopup" Placement="Mouse" HorizontalOffset="-100" VerticalOffset="-100" AllowsTransparency="True" StaysOpen="True">
<Alarms:UserControl_MYUC DataContext="{Binding TopMost}" Background="{DynamicResource DetailPanelCompartmentTitleBg}" BorderBrush="{DynamicResource SecWindowBtnBorder}"/>
</Popup>
</ContextMenu>
点击菜单项,我已经写了以下代码:
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
infoPopup.Visibility = System.Windows.Visibility.Visible;
infoPopup.IsOpen = true;
}
我可以在点击信息按钮时看到弹出窗口,但弹出窗口会在一秒钟内出现。我希望它是可见的,直到用户点击其他区域或弹出失去焦点。请建议该怎么做。
将StaysOpenOnClick="True"
应用于MenuItem。
请使用StaysOpen
布尔值来定义您想要的内容。
myPopup.StaysOpen = true;
有关更多信息,请参阅以下链接:https://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.popup.staysopen(v=vs.110).aspx