问题描述
在我的ResourceDictionary我有以下样式:
In my resourceDictionary I have a following style:
<Style TargetType="{x:Type propgrid:PropertyGridDataAccessorItem}" x:Key="{x:Type propgrid:PropertyGridDataAccessorItem}">
<Style.Triggers>
<Trigger Property="DataAccessorType" Value="Category">
<Setter Property="IsExpanded" Value="{Binding DisplayName, Converter={local:ExpandedCategoryConverter}}"/>
</Trigger>
</Style.Triggers>
</Style>
我需要一个值从我的ViewModel到ConverterParameter,像ConverterParameter = {myProperty的绑定绑定},但我们不能绑定到ConverterParameter。
I need to bind a value from my viewModel to ConverterParameter, something like ConverterParameter = {Binding MyProperty}, but we can't bind to a ConverterParameter.
我怎样才能解决这个问题呢?
How can I solve this issue?
日Thnx提前
推荐答案
正如你所发现的,你不能绑定 ConverterParameter
,因为它不是一个依赖项属性。
As you have discovered, you cannot bind ConverterParameter
because it's not a dependency property.
在大多数情况下这种情况的解决方案是简单地使用 MultiBinding
和,例如:
Most of the time the solution for this is to simply use a MultiBinding
and a multi value converter instead, for example:
<Trigger Property="DataAccessorType" Value="Category">
<Setter Property="IsExpanded">
<Setter.Value>
<MultiBinding Converter="{local:ExpandedCategoryConverter}">
<Binding Path="DisplayName"/>
<Binding Path="WhatYouWantToPassInAsConverterParameter"/>
</MultiBinding>
</Setter.Value>
</Setter>
</Trigger>
转换器当然会需要适当更新。
The converter would of course need to be updated appropriately.
这篇关于结合价值ConverterParameter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!