Formular una preguntaFormular una pregunta
 

RespondidaOr condition, multitrigger

  • domingo, 17 de junio de 2007 21:16espeholt_jr1 Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    Hi...

    Why is there not a OrCondition? or better why is Condition sealed?

    I'm trying to do something like this:

                                <Trigger Property="IsFocused" Value="True">
                                    <Trigger.EnterActions>
                                        <BeginStoryboard>
                                            <DoubleAnimation To="1.0" Storyboard.TargetProperty="Background.Opacity" Duration="0:0:1"/>
                                        </BeginStoryboard>
                                    </Trigger.EnterActions>
                                    <Trigger.ExitActions>
                                        <BeginStoryboard>
                                            <DoubleAnimation To="0.0" Storyboard.TargetProperty="Background.Opacity" Duration="0:0:1"/>
                                        </BeginStoryboard>
                                    </Trigger.ExitActions>
                                </Trigger>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Trigger.EnterActions>
                                        <BeginStoryboard>
                                            <DoubleAnimation To="1.0" Storyboard.TargetProperty="Background.Opacity" Duration="0:0:1"/>
                                        </BeginStoryboard>
                                    </Trigger.EnterActions>
                                    <Trigger.ExitActions>
                                        <BeginStoryboard>
                                            <DoubleAnimation To="0.0" Storyboard.TargetProperty="Background.Opacity" Duration="0:0:1"/>
                                        </BeginStoryboard>
                                    </Trigger.ExitActions>
                                </Trigger>

    But it does not work properly because they "overwrite" eachother... hope you know what I mean - my english is not that good Wink

    But anyway, I would like to do:

    <MultiTrigger>
        <MultiTrigger.Conditions>
           <OrCondition>
              <Condition Property="IsFocused" Value="True"/>
              <Condition Property="IsMouseOver" Value="True"/>
           </OrCondition>
        <MultiTrigger.Conditions>
        <MultiTrigger.EnterActions>
           <DoubleAnimation To="1.0" Storyboard.TargetProperty="Background.Opacity" Duration="0:0:1"/>
        </MultiTrigger.EnterActions>
        <MultiTrigger.ExitActions>
           <DoubleAnimation To="0.0" Storyboard.TargetProperty="Background.Opacity" Duration="0:0:1"/>
        </MultiTrigger.ExitActions>
    </MultiTrigger>

    But is there a better way to do it?

Respuestas

  • jueves, 21 de junio de 2007 0:04Bob Shogren - MSFT Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida

    Here's something that might work for you, using a MultiTrigger: 

    Code Snippet

    <Page
        xmlns       = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x     = "http://schemas.microsoft.com/winfx/2006/xaml">

        <Page.Resources>
            <Style x:Key="StoryKey" TargetType="{x:Type TextBox}">
                <Setter Property="Background">
                    <Setter.Value>
                        <SolidColorBrush Color="Red" Opacity="0" />
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="IsFocused"   Value="true" />
                            <Condition Property="IsMouseOver" Value="true" />
                        </MultiTrigger.Conditions>
                        <MultiTrigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation
                                            Storyboard.TargetProperty   = "(TextBox.Background).(SolidColorBrush.Opacity)"
                                            To                          = "1"
                                            Duration                    = "0:0:0.5"
                                          />
                                    </Storyboard> 
                                </BeginStoryboard>
                        </MultiTrigger.EnterActions>
                        <MultiTrigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation
                                            Storyboard.TargetProperty   = "(TextBox.Background).(SolidColorBrush.Opacity)"
                                            To                          = "0"
                                            Duration                    = "0:0:0.5"
                                          />
                                    </Storyboard> 
                                </BeginStoryboard>
                        </MultiTrigger.ExitActions>
                    </MultiTrigger>
                </Style.Triggers>
            </Style>
        </Page.Resources>

        <StackPanel>
            <TextBox Height="75" Width="150" Text="TextBox" FontSize="36" Style="{StaticResource StoryKey}" />
        </StackPanel>

    </Page>

     

     

Todas las respuestas

  • miércoles, 20 de junio de 2007 7:59Yi-Lun LuoMSFT, ModeradorMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     

    Hello, I think you can use your MultiTrigger with "and condition". You can set the Conditions to meet when IsFocused and IsMouseOver are both false, and exchange the Storyboards in EnterActions and ExitActions with each other.

  • miércoles, 20 de junio de 2007 9:59espeholt_jr1 Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    Yeah, I have tought about that, but it is rather complex :/
  • jueves, 21 de junio de 2007 0:04Bob Shogren - MSFT Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida

    Here's something that might work for you, using a MultiTrigger: 

    Code Snippet

    <Page
        xmlns       = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x     = "http://schemas.microsoft.com/winfx/2006/xaml">

        <Page.Resources>
            <Style x:Key="StoryKey" TargetType="{x:Type TextBox}">
                <Setter Property="Background">
                    <Setter.Value>
                        <SolidColorBrush Color="Red" Opacity="0" />
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="IsFocused"   Value="true" />
                            <Condition Property="IsMouseOver" Value="true" />
                        </MultiTrigger.Conditions>
                        <MultiTrigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation
                                            Storyboard.TargetProperty   = "(TextBox.Background).(SolidColorBrush.Opacity)"
                                            To                          = "1"
                                            Duration                    = "0:0:0.5"
                                          />
                                    </Storyboard> 
                                </BeginStoryboard>
                        </MultiTrigger.EnterActions>
                        <MultiTrigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation
                                            Storyboard.TargetProperty   = "(TextBox.Background).(SolidColorBrush.Opacity)"
                                            To                          = "0"
                                            Duration                    = "0:0:0.5"
                                          />
                                    </Storyboard> 
                                </BeginStoryboard>
                        </MultiTrigger.ExitActions>
                    </MultiTrigger>
                </Style.Triggers>
            </Style>
        </Page.Resources>

        <StackPanel>
            <TextBox Height="75" Width="150" Text="TextBox" FontSize="36" Style="{StaticResource StoryKey}" />
        </StackPanel>

    </Page>

     

     

  • jueves, 21 de junio de 2007 12:25espeholt_jr1 Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    Thank you Smile But in my example there will be more Multitriggers which is ogly, but I guess that's the only way...