获取和设置元素的焦点
我想做的是在刷新 BO 之前获取最后一个焦点元素并将其设置回最后一个焦点值。
这个想法如下:
//get last focus element
var x = Keyboard.FocusedElement;
//refresh my businessobject here
CallMethod();
//set the focus to my last element
FocusManager.SetFocusedElement(focusScope, x);
...但这里的问题是在调用刷新对象方法之后,我的“x”值在此过程中发生了变化。
有人遇到过这个问题吗?
What I am trying to do is get the last focus element before doing a refresh on my BO and set it back to the last focus value.
the idea is something like below:
//get last focus element
var x = Keyboard.FocusedElement;
//refresh my businessobject here
CallMethod();
//set the focus to my last element
FocusManager.SetFocusedElement(focusScope, x);
... but the problem here is after calling the refresh object method my "x" value got changed in the process.
Anyone experience this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能只分配
Keyboard.FocusedElement
因为Keyboard.FocusedElement
是引用类型。因此,一旦框架更改了Keyboard.FocusedElement
,您的副本就会发生变化。您将需要找到一种新方法来识别在调用之前获得焦点的控件,或者尝试找到有效的深度复制解决方案。You cannot just assign
Keyboard.FocusedElement
becauseKeyboard.FocusedElement
is a reference type. So as soon as the Framework changes theKeyboard.FocusedElement
, your copy changes. You will need to find a new way to identify the control that had focus before the call or try and find a deep copy solution that works.为什么不使用
Focus()
方法?或考虑使用
FocusManager.GetFocusedElement(focusScope)
...Why not use the
Focus()
method??or consider using
FocusManager.GetFocusedElement(focusScope)
...