Interaction.Behaviors不适用于按钮内容

时间:2014-06-20 08:26:06

标签: c# windows-8.1 windows-rt

我已经在XAML页面的按钮内容上创建了动画,在windows silverlight 8中。但是当我将我的项目移动到Windows Phone 8.1 RT时,按钮内容的动画无效,因为它在Silverlight电话项目中工作。 / p>

我添加了以下代码,我在silverlight phone 8中实现了这个代码。

Interaction.Behaviors代码部分不起作用..我在windows phone 8.1中添加了行为sdk参考...

我还在下面添加了三个用于交互...

      xmlns:i="using:Microsoft.Xaml.Interactivity"
      xmlns:ic="using:Microsoft.Xaml.Interactions.Core"
      xmlns:im="using:Microsoft.Xaml.Interactions.Media"

XAML

<Button x:Name="MenuButton"
                Style="{StaticResource PageNumberButtonStyle}"
                Height="180"
                Margin="10"
                Width="240"
                Click="MenuButtonClick"
                Content="{Binding CurrentPage.Number}"
                FontFamily="ms-appx:///Fonts/sesamewkshpregular.ttf#SesameWkshp Rg"
                HorizontalAlignment="Left"
                RenderTransformOrigin="0.5,0.5"
                VerticalAlignment="Bottom">
            <Button.RenderTransform>
                <CompositeTransform x:Name="MenuButtonScale"
                                    ScaleX="0"
                                    ScaleY="0" />
            </Button.RenderTransform>
        </Button>



<Page.Resources>
    <ResourceDictionary>
        <!-- PageNumberButtonStyle -->
        <Style x:Key="PageNumberButtonStyle"
               TargetType="Button">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Grid>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="FocusStates">
                                    <VisualState x:Name="Unfocused" />
                                    <VisualState x:Name="Focused" />
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="PageNumberStates">
                                    <VisualState x:Name="BindingChanged">
                                        <Storyboard>
                                            <DoubleAnimation From="1"
                                                             To="0"
                                                             Storyboard.TargetProperty="(UIElement.Opacity)"
                                                             Storyboard.TargetName="contentPresenter" />
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Grid.Background>
                                <ImageBrush Stretch="None" ImageSource="/Resources/Assets/Book-Solid.png" />
                            </Grid.Background>

                            <ContentPresenter x:Name="contentPresenter"
                                              HorizontalAlignment="Center"
                                              VerticalAlignment="Center"
                                              Margin="0,20,0,0"
                                              RenderTransformOrigin="0.5,0.5">
                                <ContentPresenter.RenderTransform>
                                    <CompositeTransform x:Name="contentTransform"
                                                        ScaleX="0.5"
                                                        ScaleY="0.5" />
                                </ContentPresenter.RenderTransform>
                            </ContentPresenter>

                            <i:Interaction.Behaviors>
                                <ic:DataTriggerBehavior Binding="{Binding CurrentPage.Number}">
                                    <im:ControlStoryboardAction ControlStoryboardOption="Play">
                                        <im:ControlStoryboardAction.Storyboard>
                                            <Storyboard>
                                                <DoubleAnimation From="0"
                                                                 To="1"
                                                                 Duration="0:0:1"
                                                                 Storyboard.TargetProperty="ScaleX"
                                                                 Storyboard.TargetName="contentTransform">
                                                    <DoubleAnimation.EasingFunction>
                                                        <ElasticEase EasingMode="EaseOut"
                                                                     Oscillations="2"
                                                                     Springiness="5" />
                                                    </DoubleAnimation.EasingFunction>
                                                </DoubleAnimation>
                                                <DoubleAnimation From="0"
                                                                 To="1"
                                                                 Duration="0:0:1"
                                                                 Storyboard.TargetProperty="ScaleY"
                                                                 Storyboard.TargetName="contentTransform">
                                                    <DoubleAnimation.EasingFunction>
                                                        <ElasticEase EasingMode="EaseOut"
                                                                     Oscillations="2"
                                                                     Springiness="5" />
                                                    </DoubleAnimation.EasingFunction>
                                                </DoubleAnimation>
                                            </Storyboard>
                                        </im:ControlStoryboardAction.Storyboard>
                                    </im:ControlStoryboardAction>
                                </ic:DataTriggerBehavior>
                            </i:Interaction.Behaviors>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="FontSize" Value="150" />

        </Style>

    

Please, guide me here for this problem..

1 个答案:

答案 0 :(得分:0)

尝试向ComparisonConditionType添加ValueDataTriggerBehaviour属性,因为它需要一个条件来对特定值进行比较。

相关问题