質問する質問する
 

回答済みOr condition, multitrigger

  • 2007年6月17日 21:16espeholt_jr1 ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    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?

回答

  • 2007年6月21日 0:04Bob Shogren - MSFT ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     回答済み

    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>

     

     

すべての返信

  • 2007年6月20日 7:59Yi-Lun LuoMSFT, モデレータユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     

    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.

  • 2007年6月20日 9:59espeholt_jr1 ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    Yeah, I have tought about that, but it is rather complex :/
  • 2007年6月21日 0:04Bob Shogren - MSFT ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     回答済み

    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>

     

     

  • 2007年6月21日 12:25espeholt_jr1 ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    Thank you Smile But in my example there will be more Multitriggers which is ogly, but I guess that's the only way...