检测在Silverlight控件的焦点 [英] Detecting a control's focus in Silverlight

查看:203
本文介绍了检测在Silverlight控件的焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法告诉控制(特别是一个System.Windows.Controls.TextBox)是否被聚焦在Silverlight?我正在寻找类似如下(你会在常规的.NET应用程序见):

  textBox.Focused 

这看起来似乎简单,琐碎,从控制离开了,但我不能找到一个回答任何地方。



更新



一个稍微更优雅的解决方案,结合罗布的回答,是创建一个扩展方法,像这样:

 公共静态布尔IsFocused(该控制的控制)
{
返回FocusManager.GetFocusedElement()==控制;
}


解决方案

您必须使用<一个HREF =htt​​p://msdn.microsoft.com/en-us/library/system.windows.input.focusmanager%5Fmembers%28VS.95%29.aspx>的FocusManager

 布尔b = FocusManager.GetFocusedElement()== textBox中; 


Is there any way to tell whether a control (specifically a System.Windows.Controls.TextBox) is focused in Silverlight? I'm looking for something like the following (what you would see in a regular .Net application):

textBox.Focused

This seems like something simple and trivial to leave out from a control, and yet I can't find an answer anywhere.

Update

A slightly more elegant solution, incorporating Rob's answer, is to create an extension method like so:

public static bool IsFocused( this Control control )
{
    return FocusManager.GetFocusedElement() == control;
}

解决方案

You have to use FocusManager

bool b = FocusManager.GetFocusedElement() == textBox;

这篇关于检测在Silverlight控件的焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆