Windows Phone DoubleAnimation for Border

时间:2016-01-24 23:47:27

标签: xaml windows-phone-8

我需要制作某种财产" EnableBlinking"对于Border元素,它允许DoubleAnimation为不透明度,间隔为。

<Border CornerRadius="5" Background="Red" EnableBlinking="True" />

我找到了示例但据我所知,Windows Phone不支持此功能。还有VisualStateManager。有人可以给我任何例子或好的教程吗?我不明白我是否需要创建Style或新元素。

由于

1 个答案:

答案 0 :(得分:0)

您可以使用先进的XAML概念,并可以使用附加属性和用户控制。

  

创建用户控件

<UserControl
    .................
         <UserControl.Resources>
                <Storyboard x:Name="storyBoard">
                    <DoubleAnimation Storyboard.TargetName="brd"
                             Storyboard.TargetProperty="Opacity"
                             From="0"
                             To="1"
                             RepeatBehavior="Forever"
                             AutoReverse="True"
                             Duration="0:0:0.1"/>
                </Storyboard>

            </UserControl.Resources>
            <Grid>
                <Border  x:Name="brd" CornerRadius="5" Background="Red"/>
            </Grid>
        </UserControl>


public sealed partial class BorderControl : UserControl
    {
        public BorderControl()
        {
            this.InitializeComponent();
        }

        public static bool GetEnableBlinking(DependencyObject obj)
        {
            return (bool)obj.GetValue(EnableBlinkingProperty);
        }

        public static void SetEnableBlinking(DependencyObject obj, bool value)
        {
            obj.SetValue(EnableBlinkingProperty, value);
        }

        // Using a DependencyProperty as the backing store for EnableBlinking.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty EnableBlinkingProperty =
            DependencyProperty.RegisterAttached("EnableBlinking", typeof(bool), typeof(MainPage), new PropertyMetadata(0, (s, e) =>
            {
                (s as BorderControl).storyBoard.Begin();
            }));
    } 



 MainPage.xaml
<Grid>
        <local:BorderControl EnableBlinking="true" HorizontalAlignment="Center" VerticalAlignment="Center" Height="100" Width="100"/>
    </Grid>

这是源代码: https://onedrive.live.com/?id=58D8C7A3527E52FB%21105&cid=58D8C7A3527E52FB