绑定converterParameter值 [英] Binding a converterParameter value

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

问题描述

大家好,

我有以下xaml代码,我试图绑定converterParameter值:

Hi all,
I have following xaml code where I am trying to bind converterParameter value:

<Window.Resources>
    <ResourceDictionary>
        <local:ExpandedCategoryConverter x:Key="ExpandConverter"/>
        <Style TargetType="{x:Type propgrid:PropertyGridDataAccessorItem}">
            <Style.Triggers>
                <Trigger Property="DataAccessorType" Value="Category">
                    <Setter Property="IsExpanded">
                        <Setter.Value>
                            <MultiBinding Converter="{StaticResource ExpandConverter}">
                                <Binding Path="DisplayName"/>
                                <Binding Path="ExpandCategory"/>
                            </MultiBinding>
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </Style.Triggers>
        </Style>  
    </ResourceDictionary>
</Window.Resources>





问题是我想绑定ExpandCategory不是来自 TargetType ={x:Type propgrid:PropertyGridDataAccessorItem},而是来自我的viewModel。

我该怎么做?

Thnx提前



The problem is that I want to bind ExpandCategory not from TargetType="{x:Type propgrid:PropertyGridDataAccessorItem}", but from my viewModel.
How can I do that?
Thnx in advance

推荐答案

解决方案非常简单 - 我只是在Mode = FindAncestor中将RelativeSource添加到我的绑定中。

代码现在看起来如此:



The solution was very simple - I just added RelativeSource to my binding in Mode = FindAncestor.
Code looks now so:

<window.resources>
    <resourcedictionary>
        <style targettype="{x:Type propgrid:PropertyGridDataAccessorItem}">
            <style.triggers>
                <trigger property="DataAccessorType" value="Category">
                    <setter property="IsExpanded">
                        <setter.value>
                            <multibinding>
                                <multibinding.converter>
                                    <local:expandedcategoryconverter  />
                                </multibinding.converter>
                                <binding path="DisplayName" relativesource="{RelativeSource Self}" />
                                <binding path="ViewModel" relativesource="{RelativeSource Mode=FindAncestor, AncestorType=Window}" />
                            </multibinding>
                        </setter.value>
                    </setter>
                </trigger>
            </style.triggers>
        </style>  
    </resourcedictionary>
</window.resources>


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

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