每当我尝试使用屏幕键盘在WPF窗口内的弹出窗口内的TextBox中键入文本时,弹出窗口就会关闭。
使用以下代码可以轻松复制行为。
MainWindow.xaml.cs
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Popup.StaysOpen = false;
Open.Click += (e, sender) =>
{
Popup.IsOpen = true;
Text.Focus();
};
Close.Click += (e, sender) =>
{
Popup.IsOpen = false;
Open.Focus();
};
}
}
MainWindow.xaml
<Window x:Class="WpfApplication.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid VerticalAlignment="Center" HorizontalAlignment="Center">
<Button x:Name="Open" Padding="16 9" Background="#FFFF00">Open</Button>
<Popup x:Name="Popup">
<Border Background="#FF00FF" Padding="16 9">
<StackPanel>
<TextBox x:Name="Text" Width="300" Margin="0 0 0 9" Padding="16 9" />
<Button HorizontalAlignment="Right" x:Name="Close" Padding="16 9" Background="#00FFFF">Close</Button>
</StackPanel>
</Border>
</Popup>
</Grid>
</Grid>
</Window>
是否有可能在不设置Popup.StaysOpen = true
的情况下阻止Windows的屏幕键盘关闭弹出窗口?