在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>
答案 0 :(得分:1)
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;
}
这是我选中的弹出窗口