Home > database >  TextBox Text IMultiValueConverter and additional binding parameters
TextBox Text IMultiValueConverter and additional binding parameters

Time:09-23

I have a TextBox that looks something like this:-

<TextBox Text="{Binding Scale, NotifyOnValidationError=True, 
               UpdateSourceTrigger=LostFocus, NotifyOnSourceUpdated=True, StringFormat={}{0:g5}}" />

I'd like to use a multi value converter for the Text property, as I want to bind StringFormat rather than hardcode it in xaml (similar to this). Am I right in saying that using such a converter leaves me with no way to specify further binding expression "parameters", such as NotifyOn... and UpdateSourceTrigger seen in my example? (I realise the UpdateSourceTrigger default is LostFocus, but there might be times where I'd want to use PropertyChanged, for example).

CodePudding user response:

Am I right in saying that using such a converter leaves me with no way to specify further binding expression "parameters" ...?

No, MultiBinding does also have all these properties, and you specify them like this:

<TextBox>
    <TextBox.Text>
        <MultiBinding Converter="{StaticResource YourConverter}"
                      NotifyOnValidationError="True"
                      NotifyOnSourceUpdated="True"
                      UpdateSourceTrigger="LostFocus">
            <Binding Path="Scale"/>
            <Binding Path="YourStringFormat"/>
        </MultiBinding>
    </TextBox.Text>
</TextBox>
  • Related