是否有可能使用触发器二传手改变视图模型的财产? [英] Is it possible to use trigger setter to change ViewModel property?

查看:163
本文介绍了是否有可能使用触发器二传手改变视图模型的财产?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用打开弹出 ISOPEN 绑定到其他的难以达到的附加属性。所有我想要的是 ISOPEN 价值在某种程度上传递给视图模型。

I am opening Popup using IsOpen bound to some hard to reach attached property. All I want is to somehow pass IsOpen value to ViewModel.

尝试使用二传手这个:

<Popup StaysOpen="False"
       IsOpen="{Binding Path=(local:ListViewBehavior.IsColumnHeaderClicked), RelativeSource={RelativeSource FindAncestor, AncestorType=GridViewColumnHeader}}">
    <Popup.Style>
        <Style TargetType="Popup">
            <Style.Triggers>
                <Trigger Property="IsOpen" Value="True">
                    <!-- this is not possible -->
                    <Setter Property="{Binding IsPopupOpened ...}" Value="True" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </Popup.Style>
</Popup>

给出:

一个绑定不能在类型的'财产'属性'二传手'设置。 A'绑定'只能在DependencyObject的一个的DependencyProperty设置。

A 'Binding' cannot be set on the 'Property' property of type 'Setter'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.

有没有办法通过 ISOPEN 值(已绑定到其他的视图的东西),以视图模型?

Is there a way to pass IsOpen value (which is already bound to something else in the View) to ViewModel?

推荐答案

您可以创建一个附加属性,这是由事件处理器到弹出的打开和关闭事件设置。这可以通过绑定OneWayToSource被绑定到你的视图模型的IsPopupOpen属性。
我也不太清楚,如果有一个简单的解决方案,但是这是一种替代方法我会做什么,因为没有人在这里提供了一个更好的解决方案的情况下。

You could created an attached Property, which is set by eventhandlers to the Opened and Closed Events of the Popup. That can be bind to the IsPopupOpen Property of your ViewModel by OneWayToSource Binding. I'm also not quite sure if there is an easier Solution, but this is a kind of "Workaround" what I would do, in case that no-one provides a better solution here.

这篇关于是否有可能使用触发器二传手改变视图模型的财产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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