WPF MVVM对象绑定。 [英] WPF MVVM Object binding.

查看:270
本文介绍了WPF MVVM对象绑定。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题。

我在我的xaml上使用了一些外部控件,我需要调用他的函数

我的视图模型。

i在我的视图模型中从他的类型创建了一个属性,我想绑定它们。

如何绑定一个对象?



示例:我在xaml有一个文本块,我希望在代码中调用他的焦点()



我该怎么办?



谢谢,Ofer。

Hi, I encountered a problem.
i'm working with some outer control at my xaml, and i need to call to his functions from
my view model.
i created a property from his type at my view model and i want to bind them.
how can i bind an object?

Example: i have a Text Block at xaml and i want in code to call to his focus()

how can i do it?

Thanks, Ofer.

推荐答案

你不能轻易做你想做的事 - 设置专注于一个特定的控件一般都是MVVM的痛苦。



这也违背了MVVM的全部意义 - 虚拟机应该不会真正知道焦点将会是什么设置完毕。



如果你确实需要这样做,你可以使用附加属性 - 参见 here [ ^ ]



但是,根据您的应用程序,在某些事件或其他事件中将焦点设置在代码后面可能会更简单。
You can't do what you are trying easily - setting the focus to a particular control is a pain in MVVM generally.

It also goes against what MVVM is all about - the VM shouldn't really know focus is going to be set at all.

If you do need to do it, you can use attached properties - see here[^]

But, depending on your application, it may be simpler to set the focus in code behind on some event or other.


这篇关于WPF MVVM对象绑定。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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