Fazer uma PerguntaFazer uma Pergunta
 

RespondidoMultiDataTrigger Lack Of OR support

  • terça-feira, 29 de janeiro de 2008 12:52BenPatt Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    What I want to do is simple:

     

    <DataTemplate.Triggers>

    <MultiDataTrigger>

    <MultiDataTrigger.Conditions>

    <ORConditionGroup>

    <Condition Binding ="{Binding IsA}" Value="True"/>

    <Condition Binding="{Binding IsB}" Value="True"/>

    </ORConditionGroup>

    </MultiDataTrigger.Conditions>

    <Setter TargetName ="CellButton" Property ="Background" Value="White"/>

    </MultiDataTrigger>

    </DataTemplate.Triggers>

     

    Except of course the OR Condition group doesn't exist. So I can't. Can anybody suggest a way to achieve this that doesn't involve duplicating the setter code (My actual use involves 6 or so setters, besides that sucks)

     

    An alternative for me that also isn't implemented is multiple values, thus:

     

    <Condition Binding="{Binding MyValue}">

    <Condition.Value>

    <UI:CodeWordControlMode>

    Debug

    </UI:CodeWordControlMode>

    </Condition.Value>

     

    <Condition.Value>

    <UI:CodeWordControlMode>

    Text

    </UI:CodeWordControlMode>

    </Condition.Value>

    </Condition>

     

     

    Any work arounds to achieve this?

    I'm really suprised that this stuff isn't already implemented in the XAML. It seems like basic functionality to me.

     

    Doing the comparison in C# code and then looking at the boolean result is not really an option, for various reasons.

     

    Loads of other people must be hitting this, so I assume I missing something pretty huge.

Respostas

  • terça-feira, 29 de janeiro de 2008 13:22Kent BoogaartMVPMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido
    The post was about doing an OR condition inside MultiDataTrigger.Conditions not inside a standard binding, but Mario's suggestion of using a MultiBinding can still be made to work:

    Code Snippet

    <DataTemplate.Triggers>

    <MultiDataTrigger>

    <MultiDataTrigger.Conditions>

    <Condition>

    <Condition.Binding>

    <MultiBinding Converter="{StaticResource OrConverter}">
    <Binding Path="IsA"/>
    <Binding Path="IsB"/>
    </MultiBinding>

    </Condition.Binding>

    </Condition>

    </MultiDataTrigger.Conditions>

    <Setter TargetName ="CellButton" Property ="Background" Value="White"/>

    </MultiDataTrigger>

    </DataTemplate.Triggers>


    HTH,
    Kent
  • terça-feira, 29 de janeiro de 2008 13:50Charles PetzoldMVPMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido

    Remember Augustus de Morgan's theorem:  "The contrary of an aggregate is the compound of the contraries of the aggregants: the contrary of a compound is the aggregate of the contraries of the components."

     

    In other words, when you negate everything, AND changes to OR and vice versa.  In this particular example,

    • Change the default Background property of CellButton to White
    • In the two Condition elements, change Value from "True" to "False."
    • In the Setter element, change Value to the color you want normally (the non-White color).

    With these changes, the MultiTrigger will be satisfied only if both bindings are false, and the color will be set to the non-White value.  If either binding becomes true, then the MultiTrigger will not be satisfied, and the color will revert to the value set to the Background property (that is, White).

     

     

     

     

Todas as Respostas

  • terça-feira, 29 de janeiro de 2008 13:09Mario M_ Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    Hi!

     

    How about using a Converter?

     

    Code Snippet

     

    <CellButton.Background>

    <MultiBinding Converter="{StaticResource MyConverter}" Mode="OneWay">

    <Binding ElementName="A" Path="IsChecked"/>

    <Binding ElementName="B" Path="IsChecked"/>

    </MultiBinding>

    </CellButton.CellButton>

     

     

    Cheers,

     

    Mario M.

     

  • terça-feira, 29 de janeiro de 2008 13:22Kent BoogaartMVPMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido
    The post was about doing an OR condition inside MultiDataTrigger.Conditions not inside a standard binding, but Mario's suggestion of using a MultiBinding can still be made to work:

    Code Snippet

    <DataTemplate.Triggers>

    <MultiDataTrigger>

    <MultiDataTrigger.Conditions>

    <Condition>

    <Condition.Binding>

    <MultiBinding Converter="{StaticResource OrConverter}">
    <Binding Path="IsA"/>
    <Binding Path="IsB"/>
    </MultiBinding>

    </Condition.Binding>

    </Condition>

    </MultiDataTrigger.Conditions>

    <Setter TargetName ="CellButton" Property ="Background" Value="White"/>

    </MultiDataTrigger>

    </DataTemplate.Triggers>


    HTH,
    Kent
  • terça-feira, 29 de janeiro de 2008 13:50Charles PetzoldMVPMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido

    Remember Augustus de Morgan's theorem:  "The contrary of an aggregate is the compound of the contraries of the aggregants: the contrary of a compound is the aggregate of the contraries of the components."

     

    In other words, when you negate everything, AND changes to OR and vice versa.  In this particular example,

    • Change the default Background property of CellButton to White
    • In the two Condition elements, change Value from "True" to "False."
    • In the Setter element, change Value to the color you want normally (the non-White color).

    With these changes, the MultiTrigger will be satisfied only if both bindings are false, and the color will be set to the non-White value.  If either binding becomes true, then the MultiTrigger will not be satisfied, and the color will revert to the value set to the Background property (that is, White).

     

     

     

     

  • sexta-feira, 18 de setembro de 2009 12:26Bbeauchemin Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Contém Código
    It is possible to accomplish what you need, but you first need to create some need generic class to accomplish some processing.

    DataTrigger (or conditions) use the Objects.Equal to compare the binding value with the "Value" parameter.
    --> Create a IsEqualConverter that take the first parameter (object) and do an Object.IsEquals with the parameter.
    --> You can create a class that will allows you to use a "Value" depency or use the ConverterParameter.
    http://msdn.microsoft.com/en-us/library/system.windows.multidatatrigger.conditions.aspx

    public object Convert(object value, Type t, object parameter, CultureInfo c)
    {
        if ( value != null )
            return value.Equals( parameter );
    
       return false;
    }
    
    Then, you need a MultiValueConverter that only do the  "or" operation on all element.


    Finnaly your OR statement in your xaml will looks like:
    <Condition Value="True">
     <Condition.Binding>
      <MulitiBinding converter={StaticResource OrMultiValueConverter}>
        <Binding Path="VarAPath" Converter={StaticResource IsEqualConverter} converterParameter={x:Static Enum.YourEnum.ENUM_VALUE}/>
        <Binding Path="VarBPath" Converter={StaticResource IsEqualConverter} converterParameter={x:Null}/>
      </MultiBinding>
     </Condition.Binding>
    <Condition>