RayOldProf
RayOldProf

Reputation: 1070

WPF CheckBox multiBinding

I need to bind a checkBox to TWO property and I think that i have to use multiBindings

so far i have this, but this doesn't work.

<CheckBox x:Name="FilterAll" Content="All">
 <CheckBox.IsChecked>
  <MultiBinding>
     <Binding Path="SearchEngineCompassLogView.FilterSearch.IsFilterAllEnable"
            Source="{StaticResource CompassLogView}">
     </Binding>

     <Binding Path="SearchEngineCompassLogView.FilterSearch.IsFilterVisible"
             Source="{StaticResource CoreServiceLogView}">
     </Binding>
  </MultiBinding>
 </CheckBox.IsChecked>
</CheckBox>

is this even possible with MultiBinding?

Upvotes: 2

Views: 8649

Answers (2)

Liz
Liz

Reputation: 8958

You could use MultiBinding. And as ethicallogics said, you must use a converter to do the actual logic of the parameters (whether you want to do AND, OR, whatever. You can see a little more about those here

I'm not sure what you are trying to affect on your checkbox, but in the end it will look something like this.

<CheckBox.IsChecked>
   <MultiBinding Converter="{StaticResource MultiBoolConverter}">
        <Binding Path="SearchEngineCompassLogView.FilterSearch.IsFilterAllEnable" Source="{StaticResource CompassLogView}"/>
        <Binding Path="SearchEngineCompassLogView.FilterSearch.IsFilterVisible"
             Source="{StaticResource CoreServiceLogView}"/>
    </MultiBinding>
</CheckBox.IsChecked>

There is also another way to do this as well, which I sometimes find useful. It's called DataTriggers. If you've done any work with Styles and Templates then you may have seen them before. Here is an example based on your question:

<CheckBox>
  <CheckBox.Style>
     <Style TargetType={x:Type CheckBox}>
        <Style.Triggers>
          <MultiDataTrigger>
             <MultiDataTrigger.Conditions>
                  <Condition Binding="{Binding Path="SearchEngineCompassLogView.FilterSearch.IsFilterAllEnable" Source="{StaticResource CompassLogView}" Value="True"/>
                  <Condition Binding="{Binding Path="SearchEngineCompassLogView.FilterSearch.IsFilterVisible" Source="{StaticResource CoreServiceLogView}" Value="True"/>
              </MultiDataTrigger.Conditions>
              <Setter Property="CheckBox.IsChecked" Value="True"/>
          </MultiDataTrigger>
        </Style.Triggers>
     </Style>
  </CheckBox.Style>
</CheckBox>

Upvotes: 6

yo chauhan
yo chauhan

Reputation: 12295

You must specify converter in MultiBinding.Multibinding

Upvotes: 2

Related Questions