从XAML设置ViewModel的属性

编程入门 行业动态 更新时间:2024-10-27 14:29:49
本文介绍了从XAML设置ViewModel的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一些 UserControl ,它是 DataContext 绑定到ViewModel,如何通过 XAML 设置ViewModel的属性?有可能吗?

I have some UserControl, It's DataContext is binded to the ViewModel, How to set a ViewModel's property from XAML? Is it possible?

UPD:抱歉,我不太清楚,我正在尝试得到这样的东西:UserControl的DataContext绑定到ViewModel,我需要将ViewModel的属性设置为某种值(例如,UserControl的Width属性).有可能吗?

UPD : Sorry for being not very clear, I'm trying to get something like this : UserControl's DataContext is binded to ViewModel, I need to set ViewModel's property to something (let's say, UserControl's Width property). Is it possible?

UPD2:似乎不可能.我了解TwoWay绑定模式等,我想做的事情-将ViewModel的属性设置为UserControl的属性

UPD2: It seems to be not possible.I know about TwoWay binding mode, etc, thing I wanted to do - to set ViewModel's property to UserControl's one

这个例子应该很清楚

<Set Property={Binding SomePropertyOnViewModel} Value={Binding RelativeSource={RelativeSource Self}, Path=SomePropertyOnUserControl}>

推荐答案

如何从XAML设置ViewModel的属性?有可能吗?"

"How to set a ViewModel's property from XAML? Is it possible?"

所以,看来这是不可能的,最大可以完成-双向绑定,很不幸,这不是我想要的.总而言之,这是一个很糟糕的设计,而不是一个问题

So, that seems to be not possible, max you can accomplish - two-way binding, which is, unfortunately not I wanted. All in all it's rather bad design than a problem

更多推荐

从XAML设置ViewModel的属性

本文发布于:2023-11-14 16:30:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1587960.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   XAML   ViewModel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!