如何从Style.Triggers升级到Interaction.Behaviors?

时间:2014-12-18 20:11:45

标签: c# wpf windows-runtime windows-phone

我需要将基于WinRT的WPF上的应用程序更新到WinPhone 8.1,但我不知道如何在新的WinRT上使用触发器的“新API”...

让我解释一下!

如何在WPF中编写此代码:

<Style.Triggers>
    <DataTrigger Binding="{Binding Path=IsInBubbleGroup}" Value="True">
        <DataTrigger.EnterActions>
            <BeginStoryboard>
                <Storyboard>
                    <thriple:EasingDoubleAnimation Storyboard.TargetProperty="RenderTransform.(ScaleTransform.ScaleX)" Duration="0:0:0.2" Equation="CubicEaseInOut" To="1.1" />
          <thriple:EasingDoubleAnimation 
            Storyboard.TargetProperty="RenderTransform.(ScaleTransform.ScaleY)"
            Duration="0:0:0.2"
            Equation="CubicEaseInOut"
            To="1.1"
            />
        </Storyboard>
      </BeginStoryboard>
    </DataTrigger.EnterActions>
    <DataTrigger.ExitActions>
      <BeginStoryboard>
        <Storyboard>
          <thriple:EasingDoubleAnimation 
            Storyboard.TargetProperty="RenderTransform.(ScaleTransform.ScaleX)"
            Duration="0:0:0.1"
            Equation="CubicEaseInOut"
            To="1"
            />
          <thriple:EasingDoubleAnimation 
            Storyboard.TargetProperty="RenderTransform.(ScaleTransform.ScaleY)"
            Duration="0:0:0.1"
            Equation="CubicEaseInOut"
            To="1"
            />
        </Storyboard>
      </BeginStoryboard>
    </DataTrigger.ExitActions>
  </DataTrigger>
</Style.Triggers>

对于基于WinRT的WP8.1使用Interaction.Behaviors?

我的尝试是:

<i:Interaction.Behaviors>
    <c:DataTriggerBehavior Binding="{Binding Path=IsInBubbleGroup}" Value="True">
        <c:DataTriggerBehavior.Actions>
            <BeginStoryboard>
                <Storyboard>
                    <!--EnterActions-->

                    <DoubleAnimation Storyboard.TargetProperty="RenderTransform.(ScaleTransform.ScaleX)" Duration="0:0:0.2" To="1.1">
                        <DoubleAnimation.EasingFunction>
                            <CubicEase EasingMode="EaseInOut" />
                        </DoubleAnimation.EasingFunction>
                    </DoubleAnimation>

                    <DoubleAnimation Storyboard.TargetProperty="RenderTransform.(ScaleTransform.ScaleY)" Duration="0:0:0.2" To="1.1">
                        <DoubleAnimation.EasingFunction>
                            <CubicEase EasingMode="EaseInOut" />
                        </DoubleAnimation.EasingFunction>
                    </DoubleAnimation>

                    <!--ExitActions-->

                    <DoubleAnimation Storyboard.TargetProperty="RenderTransform.(ScaleTransform.ScaleX)" Duration="0:0:0.1" To="1">
                        <DoubleAnimation.EasingFunction>
                            <CubicEase EasingMode="EaseInOut" />
                        </DoubleAnimation.EasingFunction>
                    </DoubleAnimation>

                    <DoubleAnimation Storyboard.TargetProperty="RenderTransform.(ScaleTransform.ScaleY)" Duration="0:0:0.1" To="1">
                        <DoubleAnimation.EasingFunction>
                            <CubicEase EasingMode="EaseInOut" />
                        </DoubleAnimation.EasingFunction>
                    </DoubleAnimation>

                </Storyboard>
            </BeginStoryboard>                    
        </c:DataTriggerBehavior.Actions>
    </c:DataTriggerBehavior>
</i:Interaction.Behaviors>

但我不知道如何创建进入和退出操作..请帮助我

2 个答案:

答案 0 :(得分:1)

这似乎是一个简单的答案,但你不能像这样创建一个触发器:

<c:DataTriggerBehavior Binding="{Binding Path=IsInBubbleGroup}" Value="True">
....
</c:DataTriggerBehavior>

等同于 EnterActions ,然后创建另一个:

<c:DataTriggerBehavior Binding="{Binding Path=IsInBubbleGroup}" Value="False">
....
</c:DataTriggerBehavior>

这相当于 ExitActions ? (注意上一个例子中的假值)

答案 1 :(得分:1)

以下是基于@Mark答案的最终答案:

<i:Interaction.Behaviors>
    <!--#Region EnterActions-->
        <c:DataTriggerBehavior Binding="{Binding Path=IsInBubbleGroup}" Value="True">
            <m:ControlStoryboardAction ControlStoryboardOption="Play">
                <m:ControlStoryboardAction.Storyboard>
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetProperty="RenderTransform.(ScaleTransform.ScaleX)" Duration="0:0:0.2" To="1.1">
                            <DoubleAnimation.EasingFunction>
                                <CubicEase EasingMode="EaseInOut" />
                            </DoubleAnimation.EasingFunction>
                        </DoubleAnimation>

                        <DoubleAnimation Storyboard.TargetProperty="RenderTransform.(ScaleTransform.ScaleY)" Duration="0:0:0.2" To="1.1">
                            <DoubleAnimation.EasingFunction>
                                <CubicEase EasingMode="EaseInOut" />
                            </DoubleAnimation.EasingFunction>
                        </DoubleAnimation>
                    </Storyboard>
                </m:ControlStoryboardAction.Storyboard>
            </m:ControlStoryboardAction>
        </c:DataTriggerBehavior>
        <!--#EndRegion EnterActions-->

        <!--#Region ExitActions-->
        <c:DataTriggerBehavior Binding="{Binding Path=IsInBubbleGroup}" Value="False">
            <m:ControlStoryboardAction ControlStoryboardOption="Stop">
                <m:ControlStoryboardAction.Storyboard>
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetProperty="RenderTransform.(ScaleTransform.ScaleX)" Duration="0:0:0.1" To="1">
                            <DoubleAnimation.EasingFunction>
                                <CubicEase EasingMode="EaseInOut" />
                            </DoubleAnimation.EasingFunction>
                        </DoubleAnimation>

                        <DoubleAnimation Storyboard.TargetProperty="RenderTransform.(ScaleTransform.ScaleY)" Duration="0:0:0.1" To="1">
                            <DoubleAnimation.EasingFunction>
                                <CubicEase EasingMode="EaseInOut" />
                            </DoubleAnimation.EasingFunction>
                        </DoubleAnimation>
                    </Storyboard>
                </m:ControlStoryboardAction.Storyboard>
            </m:ControlStoryboardAction>
        </c:DataTriggerBehavior>
    <!--#EndRegion ExitActions-->
</i:Interaction.Behaviors>