弹出窗口不适用于 MenuItem

Popup not working on MenuItem

我必须在单击 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>

MenuItem的OnClick,我写了下面的代码:

private void MenuItem_Click(object sender, RoutedEventArgs e)
{
    infoPopup.Visibility = System.Windows.Visibility.Visible;
    infoPopup.IsOpen = true;
}

我可以在单击“信息”按钮时看到弹出窗口,但弹出窗口会在一秒钟内消失。我希望它在用户单击其他区域或弹出窗口失去焦点之前一直可见。 请提出建议。

StaysOpenOnClick="True" 应用于您的 MenuItem。

请使用 StaysOpen 布尔值来定义您想要的内容。

myPopup.StaysOpen = true;

更多信息,请参考以下内容link:https://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.popup.staysopen(v=vs.110).aspx