wpf 绑定值作为 ConverterParameter
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16892908/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Binding value as ConverterParameter
提问by Sasha
In my resourceDictionary I have a following style:
在我的 resourceDictionary 中,我有以下风格:
<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>
I need to bind a value from my viewModel to ConverterParameter, something like ConverterParameter = {Binding MyProperty}, but we can't bind to a ConverterParameter.
我需要将 viewModel 中的值绑定到 ConverterParameter,例如 ConverterParameter = {Binding MyProperty},但我们无法绑定到 ConverterParameter。
How can I solve this issue?
我该如何解决这个问题?
Thnx in advance
提前谢谢
回答by Jon
As you have discovered, you cannot bind ConverterParameterbecause it's not a dependency property.
正如您所发现的,您无法绑定,ConverterParameter因为它不是依赖属性。
Most of the time the solution for this is to simply use a MultiBindingand a multi value converterinstead, for example:
大多数情况下,解决方案是简单地使用 aMultiBinding和多值转换器,例如:
<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.
转换器当然需要适当更新。

