简体   繁体   English

在弹出框内单击时,文本框不会失去焦点?

[英]Textbox doesn't lose focus when clicking outside of it when inside Popup?

I am working on a Windows 8.1 Store App using Windows Runtime. 我正在使用Windows运行时在Windows 8.1商店应用程序上工作。

I have a UserControl which holds a StackPanel which holds a number of TextBoxes. 我有一个UserControl,它拥有一个StackPanel,其中拥有许多TextBoxes。

When I place the UserControl on a Page and When I place the user control in a Popup I get different focus behaviour for the TextBox controls. 当我将UserControl放置在页面上以及将用户控件放置在弹出窗口中时,TextBox控件会获得不同的焦点行为。

UserControl on Page: When I click on a TextBox it is focused, when I click outside the TextBox on it's parent (StackPanel) the TextBox loses focus. 页面上的UserControl:当我单击TextBox时,它已聚焦,当我在其父级(StackPanel)上的TextBox之外单击时,TextBox失去了焦点。

UserControl in Popup: When I click on a TextBox it is focused, when I click outside the TextBox on it's parent (StackPanel) the TextBox does not lose focus. 弹出窗口中的UserControl:当我单击一个TextBox时,它已聚焦,当我在其父级(StackPanel)上的TextBox之外单击时,TextBox不会失去焦点。

What I want is for it to behave the same in the Popup as it does when on the Page. 我想要的是它在弹出窗口中的行为与在页面上时的行为相同。

What is causing this behaviour when the UserControl is in a Popup and how can I get it to behave the same as it does on the page when in the Popup? 是什么原因导致UserControl出现在弹出窗口中?如何使它的行为与弹出窗口中出现的页面相同?

It likely has something to do with the z-index of the popup. 它可能与弹出窗口的z-index有关。 I think you should try to detect when the mouse is clicked outside of the popup and change focus at that time. 我认为您应该尝试检测何时在弹出窗口之外单击鼠标,并在那时更改焦点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM