microsoft / XamlBehaviors

This is the official home for UWP XAML Behaviors on GitHub.
MIT License
702 stars 112 forks source link

Add Otherwise property to DataTriggerBehavior #97

Closed silverdragon727 closed 8 years ago

silverdragon727 commented 8 years ago

The Otherwise property provides with a straight-forward method for adding actions to be executed when the condition is not satisfied.

msftclas commented 8 years ago

Hi @silverdragon727, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! In order for us to evaluate and accept your PR, we ask that you sign a contribution license agreement. It's all electronic and will take just minutes. I promise there's no faxing. https://cla.microsoft.com.

TTYL, MSBOT;

msftclas commented 8 years ago

@silverdragon727, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR.
Thanks, MSBOT;

skendrot commented 8 years ago

This property should not be needed. The otherwise value is the value that is set on the element by default

silverdragon727 commented 8 years ago

@skendrot Well I forgot to give a reason...

Given XAML snippet below,

<CheckBox x:Name="CheckBox" />
<SymbolIcon x:Name="Icon" Symbol="Setting">
    <Interactivity:Interaction.Behaviors>
        <Interactions:DataTriggerBehavior Binding="{Binding IsChecked, ElementName=CheckBox}" Value="True">
            <Interactions:InvokeCommandAction Command="{Binding VerifyCommand}" />
            <Interactions:ChangePropertyAction PropertyName="Symbol">
                <Interactions:ChangePropertyAction.Value>
                    <Symbol>Accept</Symbol>
                </Interactions:ChangePropertyAction.Value>
            </Interactions:ChangePropertyAction>
            <Interactions:DataTriggerBehavior.Otherwise>
                <Interactions:ChangePropertyAction PropertyName="Symbol">
                    <Interactions:ChangePropertyAction.Value>
                        <Symbol>Cancel</Symbol>
                    </Interactions:ChangePropertyAction.Value>
                </Interactions:ChangePropertyAction>
            </Interactions:DataTriggerBehavior.Otherwise>
        </Interactions:DataTriggerBehavior>
    </Interactivity:Interaction.Behaviors>
</SymbolIcon>

As you can see, an Otherwise property is a convenient way to do so.

skendrot commented 8 years ago

This is already possible through the DataTriggerBehavior as such:

<SymbolIcon x:Name="Icon" Symbol="Setting">
    <Interactivity:Interaction.Behaviors>
        <Interactions:DataTriggerBehavior Binding="{Binding IsChecked, ElementName=CheckBox}" Value="True">
            <Interactions:InvokeCommandAction Command="{Binding VerifyCommand}" />
            <Interactions:ChangePropertyAction PropertyName="Symbol">
                <Interactions:ChangePropertyAction.Value>
                    <Symbol>Accept</Symbol>
                </Interactions:ChangePropertyAction.Value>
            </Interactions:ChangePropertyAction>
        </Interactions:DataTriggerBehavior>
        <Interactions:DataTriggerBehavior Binding="{Binding IsChecked, ElementName=CheckBox}" Value="False">
             <Interactions:ChangePropertyAction PropertyName="Symbol">
                 <Interactions:ChangePropertyAction.Value>
                     <Symbol>Cancel</Symbol>
                 </Interactions:ChangePropertyAction.Value>
             </Interactions:ChangePropertyAction>
        </Interactions:DataTriggerBehavior>
    </Interactivity:Interaction.Behaviors>
</SymbolIcon>