0

I have a treeview with textblocks that display some text according to a converter. I want the textbox to update according to a property that is not used in the converter, but is also a property of the object sent to the converter.

The following is my textblock in a hierearchy template in my treeview:

<TextBlock Text="{Binding Converter={StaticResource EntityIDToStrConverter},UpdateSourceTrigger=}" Margin="6" TextAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center"/>

This converter uses 3 different properties of the object to return a string according to what I need. So usually I have my textblock binded to a path like the following:

<TextBlock Text="{Binding Binding Path=Name, Converter={StaticResource EntityIDToStrConverter},UpdateSourceTrigger=}" Margin="6" TextAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center"/>

But that would not allow my object to pass to the converter, and rather only the Name property. How could I make the binding sensitive to changes of a specific property while still passing the entire object to the converter?

PigSpider
  • 881
  • 9
  • 18
  • 1
    Use a `` (https://stackoverflow.com/questions/2552853/how-to-bind-multiple-values-to-a-single-wpf-textblock) to bind against the 3 different properties directly. The converter would then need to be based on [`IMultiValueConverter`](https://learn.microsoft.com/en-us/dotnet/api/system.windows.data.imultivalueconverter?view=netframework-4.7.2)... –  Feb 18 '19 at 19:16
  • Thanks, that works. – PigSpider Feb 18 '19 at 19:46

1 Answers1

1

Multibindings gave me the ability to allow multiple property's value change events make this binding update for each of them.

Here's my xaml code:

   <TextBlock.Text>
          <MultiBinding Converter="{StaticResource DataClassMultiValueConverter}">
                <Binding Path="StationID" NotifyOnSourceUpdated="True"/>
                <Binding Path="DeviceID" NotifyOnSourceUpdated="True"/>
                <Binding Path="SubDeviceID" NotifyOnSourceUpdated="True"/>
          </MultiBinding>
  </TextBlock.Text>
PigSpider
  • 881
  • 9
  • 18