Results 1 to 2 of 2

Thread: [RESOLVED] MultiBinding to multiple properties on the ViewModel with converters

  1. #1

    Thread Starter
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,904

    Resolved [RESOLVED] MultiBinding to multiple properties on the ViewModel with converters

    Hi All

    I think this is probably quite easy but I can't get the syntax right. I have a button and it's enabled property depends on two states in the ViewModel. 1. That an Algorithm has been loaded and 2. That Model Runs exist.

    From the accepted answer to this post on SO, I believe I can use a MultiBinding with a Converter to flip to multiple conditions into a single boolean. Looks good.

    The problem I'm facing is that all examples I'm seeing for this use bindings to a boolean properties of elements in the view. E.g.:-
    xaml Code:
    1. <MultiBinding Converter="{StaticResource booleanAndConverter}">
    2.       <Binding ElementName="SomeCheckBox" Path="IsChecked" />
    3.       <Binding ElementName="AnotherCheckbox" Path="IsChecked"  />
    4.     </MultiBinding>

    In my case I need to bind to two non boolean states on the view model, each with a converter that converts it to a bool.

    E.g. I have another button that is enabled based on the first of the conditions (that an algorithm is loaded) for which the IsEnabled binding looks like this:-
    xaml Code:
    1. IsEnabled="{Binding AnalysisConfiguration.AlgorithmConfiguration, Converter={StaticResource NotNullNullToTrueFalseConverter}}"

    So my full multi binding should look something like:-
    xaml Code:
    1. <Button.IsEnabled>
    2.                     <MultiBinding Converter="{StaticResource BooleanAndConverter}">
    3.                         <Binding AnalysisConfiguration.AlgorithmConfiguration, Converter={StaticResource NotNullNullToTrueFalseConverter} />
    4.                         <Binding ModelRuns.Count, Converter={StaticResource GreaterThanZeroToBooleanConverter  />
    5.                     </MultiBinding>
    6.                 </Button.IsEnabled>

    I've tried various ways of phrasing this but they're all giving me syntax errors.
    Last edited by FunkyDexter; Feb 2nd, 2023 at 06:51 AM.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  2. #2

    Thread Starter
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,904

    Re: MultiBinding to multiple properties on the ViewModel with converters

    Sometimes you can stare at something all day and still miss the bleeding obvious. I'd just missed out some quotes:-
    xaml Code:
    1. <MultiBinding Converter="{StaticResource BooleanAndConverter}">
    2.                         <Binding Path="AnalysisConfiguration.AlgorithmConfiguration" Converter="{StaticResource NotNullNullToTrueFalseConverter}" />
    3.                         <Binding Path="ModelRuns.Count" Converter="{StaticResource GreaterThanZeroToBooleanConverter}" />
    4.                     </MultiBinding>
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width