本文介绍了WPF的MVVM:从视图模型设置UI控件焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是MVVM架构设置控制的重点一个很好的做法。

What is a good practice of setting control focus in MVVM architecture.

我想象它的样子是在视图模型的属性需要时,将触发焦点变化。比有控件绑定/用户界面听那个属性,因此,如果它的变化,适当的焦点将被设置。

The way I envision it, is with a property on the ViewModel that would trigger a focus change when needed. And than have the UI controls bind/listen to that property so that if it changes, appropriate focus will be set.

我认为这是一个ViewModel的事情,因为我想成立后,由视图模型执行特定操作,如加载某些数据集中适当的。

I see it as a ViewModel thing, because i want to set focus appropriate after a certain action was performed by the ViewModel, such as loading certain data.

什么是最好的做法?

推荐答案

使用的IsFocused附加属性在这里回答提示:的

Use the IsFocused Attached Property as suggested in the Answer here: Set focus on textbox in WPF from view model (C#) & wPF

然后,你可以简单地绑定到您的视图模型的属性。

Then you can simply bind to a property in your viewmodel.

这篇关于WPF的MVVM:从视图模型设置UI控件焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 13:17