Sasha
Sasha

Reputation: 853

Binding value as ConverterParameter

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>

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 in advance

Upvotes: 1

Views: 8994

Answers (1)

Jon
Jon

Reputation: 437326

As you have discovered, you cannot bind ConverterParameter because it's not a dependency property.

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.

Upvotes: 6

Related Questions