gpt4 book ai didi

c# - 当鼠标在弹出窗口外单击时如何防止弹出窗口关闭

转载 作者:行者123 更新时间:2023-11-30 17:27:02 25 4
gpt4 key购买 nike

在 WPF 中,当我们单击“切换”按钮时,弹出窗口会正确打开,但当我们单击弹出窗口外部时,弹出窗口会自动关闭。如何防止这种情况。

当我们在弹出窗口外单击时,不应关闭弹出窗口。

代码:

<ToggleButton Name="TglBtn" Content="Document" /> 
<Popup IsOpen="{Binding IsChecked, ElementName=TglBtn}" StaysOpen="False" PlacementTarget="{Binding ElementName=popupDocshow}" x:Name="pop1">
<TextBlock Text="Documents" Background="Blue"/>
</Popup>

最佳答案

PopupTest.StaysOpen = true 这就是您所缺少的。

<Popup x:Name="PopupTest" AllowsTransparency="True">
<Viewbox VerticalAlignment="Top">
<TextBlock Text="Wow, that was easy!"/>
</Viewbox>
</Popup>

private void Button_Click(object sender, RoutedEventArgs e)
{
PopupTest.Placement = System.Windows.Controls.Primitives.PlacementMode.Mouse;
PopupTest.StaysOpen = true;
PopupTest.Height = 1000;
PopupTest.Width = 500;
PopupTest.IsOpen = true;
}

这是我检查过的弹出窗口

关于c# - 当鼠标在弹出窗口外单击时如何防止弹出窗口关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55572122/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com