UWP 替代 WPF 的 IsKeyboardFocusWithin 属性
UWP alternative for WPF's IsKeyboardFocusWithin property
WPF IsKeyboardFocusWithin 属性 是否有 UWP 替代品?如果不是,您将如何确定焦点是否在其内部。
我宁愿不手动走下可视化树检查每个元素是否聚焦...
FocusManager.GetFocusedElement will ID the focused element. You can then walk up the Visual Tree with VisualTreeHelper.GetParent 看看它是否是您感兴趣的控件的子控件。向上走比逐个节点检查整个树的重量要轻得多。
类似于:
bool IsKeyboardFocusWithin(UIElement element)
{
UIElement focused = FocusManager.GetFocusedElement() as UIElement;
while (focused != null)
{
if (focused == element)
{
return true;
}
focused = VisualTreeHelper.GetParent(focused) as UIElement;
}
return false;
}
WPF IsKeyboardFocusWithin 属性 是否有 UWP 替代品?如果不是,您将如何确定焦点是否在其内部。
我宁愿不手动走下可视化树检查每个元素是否聚焦...
FocusManager.GetFocusedElement will ID the focused element. You can then walk up the Visual Tree with VisualTreeHelper.GetParent 看看它是否是您感兴趣的控件的子控件。向上走比逐个节点检查整个树的重量要轻得多。
类似于:
bool IsKeyboardFocusWithin(UIElement element)
{
UIElement focused = FocusManager.GetFocusedElement() as UIElement;
while (focused != null)
{
if (focused == element)
{
return true;
}
focused = VisualTreeHelper.GetParent(focused) as UIElement;
}
return false;
}