[英]LostFocus not firing
Got a bit stuck and could use some help. 有点卡住了,可以使用一些帮助。 To achieve: whenever click outside of the StackPanel - it Visibilty should change to Hidden.
要实现:每当在StackPanel外部单击时,“可见性”应更改为“隐藏”。
Pretty easy one, I wrote the next condition: 很简单,我写下了下一个条件:
private void pnlLeftMenu_LostFocus(object sender, RoutedEventArgs e)
{
if (pnlLeftMenu.IsFocused == false)
{
pnlLeftMenu.Visibility = Visibility.Hidden;
}
}
Where pnlLeftMenu is the panel, which should be triggered. 其中pnlLeftMenu是面板,应触发该面板。 Here is the xaml piece, with described properties:
这是xaml片段,具有描述的属性:
<StackPanel x:Name="pnlLeftMenu"
Orientation="Vertical"
Height="475"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
Margin="57,0,0,0"
Visibility="Hidden"
Background="{StaticResource BlueFadedBrush}"
IsVisibleChanged="pnlLeftMenu_IsVisibleChanged"
Focusable="True"
LostFocus="pnlLeftMenu_LostFocus" >
No worries about the fact, that it is already hidden - it is a side menu, which become vissible on button click. 不用担心,它已经被隐藏了-它是一个侧面菜单,单击按钮即可看到。 That part works fine.
那部分工作正常。
So the question is: what am I missing? 所以问题是:我想念什么? Cause when it looks like this - the click outside of the panel does't give any reaction.
原因如下:面板外部的点击没有任何反应。
can you add a click event to the parent container of stack panel and inside the click event handler try like 您可以将click事件添加到堆栈面板的父容器,并在click事件处理程序内部尝试像
if (pnlLeftMenu.IsVisible)
{
pnlLeftMenu.Visibility = Visibility.Hidden;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.