none
Popup中的TextBox失去焦点,软键盘不消失? RRS feed

  • 问题

  • 场景是这样的,Popup中显示了TextBox,当触摸TextBox外(还在Popup区域),软键盘不消息,通过测试发现这现TextBox并没有失去焦点,点击Popup区域外才失去焦点,这个怎么处理呢?

    代码如下:

     protected override void OnNavigatedTo(NavigationEventArgs e)
            {
                Popup PopupPasswordWindow = new Popup();

                PopupPasswordWindow.VerticalOffset = Windows.UI.Xaml.Window.Current.CoreWindow.Bounds.Height / 3;
                PopupPasswordWindow.Width = Windows.UI.Xaml.Window.Current.CoreWindow.Bounds.Width;
                PopupPasswordWindow.HorizontalOffset = 0;
               
                Canvas cav = new Canvas();
                cav.Height = 300;
                cav.Width = Windows.UI.Xaml.Window.Current.CoreWindow.Bounds.Width;
                cav.Background = new SolidColorBrush(Colors.White);
                TextBox TBOX = new TextBox();
                TBOX.FontSize = 30;
                TBOX.Width = 200;
                TBOX.VerticalAlignment = VerticalAlignment.Center;
                TBOX.HorizontalAlignment = HorizontalAlignment.Center;
                TBOX.BorderBrush = new SolidColorBrush(Colors.Black);
                cav.Children.Add(TBOX);
                PopupPasswordWindow.Child = cav;           
               
                PopupPasswordWindow.IsLightDismissEnabled = false;
                PopupPasswordWindow.IsOpen = true;
            }

    请指教?

    2012年10月12日 2:45

答案

  • 这个问题我也碰到过了。。我解决方式是:在popup区域里面放个宽度为0,高度为0的控件,用pointpress事件,将焦点聚焦到那个控件上去。就能使textbox失去焦点

    原因是popup不能获取焦点,所以不能使TextBox失去焦点,故键盘也无法收起来

    2012年10月12日 2:51