Stellen Sie eine FrageStellen Sie eine Frage
 

BeantwortetOr condition, multitrigger

  • Sonntag, 17. Juni 2007 21:16espeholt_jr1 TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    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?

Antworten

  • Donnerstag, 21. Juni 2007 00:04Bob Shogren - MSFT TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     Beantwortet

    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>

     

     

Alle Antworten

  • Mittwoch, 20. Juni 2007 07:59Yi-Lun LuoMSFT, ModeratorTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     

    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.

  • Mittwoch, 20. Juni 2007 09:59espeholt_jr1 TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    Yeah, I have tought about that, but it is rather complex :/
  • Donnerstag, 21. Juni 2007 00:04Bob Shogren - MSFT TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     Beantwortet

    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>

     

     

  • Donnerstag, 21. Juni 2007 12:25espeholt_jr1 TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    Thank you Smile But in my example there will be more Multitriggers which is ogly, but I guess that's the only way...