我观察到当Popup控件失去焦点时,它会将焦点返回到启动Popup的对象。所以基本上是这一系列的事件。
Textbox GotFocus触发,我打开弹出窗口
完成Popup用户点击Popup外的任何地方以激活LostFocus
LostFocus激活,但在步骤1(文本框)中的对象的GotFocus执行后立即执行 - 重新启动弹出窗口。
我的问题是,有没有办法将焦点重置为首次启动应用时的默认值?我想阻止它将焦点返回到启动弹出窗口的控件。
编辑:我删除了LostFocus事件,因为我发现没有必要在用户点击时从视图中删除弹出窗口。
Popup p;
public MainPage()
{
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Required;
p = new Popup();
p.IsLightDismissEnabled = true;
//p.LostFocus += p_LostFocus;
}
private void m_GotFocus(object sender, RoutedEventArgs e)
{
if (p.IsOpen != true)
{
// Create some content to show in the popup. Typically you would
// create a user control.
Border border = new Border();
border.BorderBrush = new SolidColorBrush(Colors.Black);
border.BorderThickness = new Thickness(0);
StackPanel panel1 = new StackPanel();
panel1.FlowDirection = Windows.UI.Xaml.FlowDirection.LeftToRight;
panel1.Background = new SolidColorBrush(Color.FromArgb(255, 30, 30, 30));
Button button1 = new Button();
button1.Content = ".";
button1.Margin = new Thickness(5.0);
button1.BorderThickness = new Thickness(0);
button1.Background = new SolidColorBrush(Color.FromArgb(255, 90, 90, 90));
button1.Click += new RoutedEventHandler(Feedback_Click);
TextBlock textblock1 = new TextBlock();
textblock1.Text = "";
textblock1.TextWrapping = TextWrapping.WrapWholeWords;
textblock1.Margin = new Thickness(5.0);
panel1.Children.Add(textblock1);
panel1.Children.Add(button1);
border.Child = panel1;
// Set the Child property of Popup to the border
// which contains a stackpanel, textblock and button.
p.Child = border;
// Set where the popup will show up on the screen.
p.VerticalOffset = 400;
p.HorizontalOffset = 100;
// Open the popup.
p.IsOpen = true;
}
}