我有一些 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的属性
发布评论