如何从 Style.Trigger 升级到 Interaction.Behaviors

本文关键字:Interaction Behaviors Trigger Style | 更新日期: 2023-09-27 18:34:47

我需要将我在 WPF 上制作的应用程序更新到 WinPhone 8.1 基于 WinRT,但我不知道如何在新的 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>

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

如何从 Style.Trigger 升级到 Interaction.Behaviors

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

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

这将等效于输入操作,然后创建另一个:

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

这相当于退出操作?(请注意上一个示例中的 False 值(

以下是基于 @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>