获取和设置元素的焦点

发布于 2024-12-07 06:13:29 字数 343 浏览 1 评论 0原文

我想做的是在刷新 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

电影里的梦 2024-12-14 06:13:29

您不能只分配 Keyboard.FocusedElement 因为 Keyboard.FocusedElement 是引用类型。因此,一旦框架更改了 Keyboard.FocusedElement,您的副本就会发生变化。您将需要找到一种新方法来识别在调用之前获得焦点的控件,或者尝试找到有效的深度复制解决方案。

You cannot just assign Keyboard.FocusedElement because Keyboard.FocusedElement is a reference type. So as soon as the Framework changes the Keyboard.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.

够运 2024-12-14 06:13:29

为什么不使用 Focus() 方法?

//get focused element
UIElement x = Keyboard.FocusedElement as UIElement;

//refresh my businessobject here
CallMethod();

//set the focus to my last element
x.Focus();

或考虑使用FocusManager.GetFocusedElement(focusScope)...

Why not use the Focus() method??

//get focused element
UIElement x = Keyboard.FocusedElement as UIElement;

//refresh my businessobject here
CallMethod();

//set the focus to my last element
x.Focus();

or consider using FocusManager.GetFocusedElement(focusScope)...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文