简体   繁体   English

WPF CheckBox multiBinding

[英]WPF CheckBox multiBinding

I need to bind a checkBox to TWO property and I think that i have to use multiBindings 我需要将一个复选框绑定到两个属性,我认为我必须使用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? MultiBinding甚至可以实现这一点吗?

You could use MultiBinding. 您可以使用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 正如ethicallogics所说,你必须使用转换器来完成参数的实际逻辑(无论你是想做AND,还是其他什么。你可以在这里看到更多关于这些的信息。

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. 它称为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>

You must specify converter in MultiBinding. 您必须在MultiBinding中指定转换器。 Multibinding Multibinding

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM