zoukankan      html  css  js  c++  java
  • Storyboard 学习

    private Storyboard PrepareShowStory()
            {
                Storyboard story = new Storyboard();
                DoubleAnimation animation;

                animation = new DoubleAnimation();
                animation.From = 0;
                animation.To = 100;
                animation.Duration = new Duration(TimeSpan.FromMilliseconds(1000));
                Storyboard.SetTarget(animation, image1);
                //Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.Opacity)"));
                Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.Height)"));
                story.Children.Add(animation);

               

                story.AutoReverse = true;
                story.RepeatBehavior = new RepeatBehavior(3); //RepeatBehavior.Forever;

                return story;
            }

    story.AutoReverse

    是否返回,如上面的,先是从0到100,然后再自动由100到0

    animation.Duration 执行的间隔

    <!--LayoutRoot 是包含所有页面内容的根网格-->
        <Grid x:Name="LayoutRoot" Background="Transparent">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>

            <!--TitlePanel 包含应用程序的名称和页标题-->
            <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
                <TextBlock x:Name="ApplicationTitle" Text="我的应用程序" Style="{StaticResource PhoneTextNormalStyle}"/>
                <TextBlock x:Name="PageTitle" Text="页面名称" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
            </StackPanel>
            <Popup x:Name="ProgressPopup" Width="300" IsOpen="False" HorizontalAlignment="Center" 
                       VerticalAlignment
    ="Top" d:LayoutOverrides="Width, HorizontalMargin" Margin="89,203,91,0">
                <Border BorderThickness="10" BorderBrush="Black" Background="DarkGray" Padding="30,30">
                    <StackPanel>
                        <TextBlock MaxHeight="100" Foreground="White"  FontWeight="Bold"  FontSize="36" x:Name="txt" Text="1">
                                <TextBlock.Triggers> 
                                    <EventTrigger RoutedEvent="TextBlock.Loaded"> 
                                        <BeginStoryboard> <Storyboard > 
                                            <DoubleAnimation   AutoReverse="True" Duration="0:0:1"
                                         From
    ="1.0" RepeatBehavior="Forever"  Storyboard.TargetName="txt" Storyboard.TargetProperty="Opacity"   To="0.0"/>  
                                        </Storyboard> 
                                        </BeginStoryboard>                             
                                    </EventTrigger>                        
                                </TextBlock.Triggers>
                        </TextBlock>
                    </StackPanel>
                </Border>
            </Popup>
            <!--ContentPanel - 在此处放置其他内容-->
            <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
                <Image Height="246" HorizontalAlignment="Left" Margin="101,182,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="197" DataContext="{Binding}" Source="/PhoneApp1;component/Images/7.jpg" />
            </Grid>
        </Grid>

    public partial class MainPage : PhoneApplicationPage
        {
            Storyboard _timer = new Storyboard();

            Storyboard story;


            int i = 0;
            // 构造函数
            public MainPage()
            {
                InitializeComponent();
                _timer.Duration = TimeSpan.FromMilliseconds(10);
                _timer.Completed += new EventHandler(_timer_Completed);
                _timer.Begin();
                i = Convert.ToInt32(txt.Text);
            }
            void _timer_Completed(object sender, EventArgs e)
            {

                if (i <= txt.MaxHeight)
                {
                    i++;
                    this.txt.Text = i.ToString();
                    _timer.Begin();

                    return;
                }

                this.Dispatcher.BeginInvoke(new Action(() => { ProgressPopup.IsOpen = false; }));
            }

            private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
            {
                //ProgressPopup.IsOpen = true;
               
    // this.Dispatcher.BeginInvoke(new Action(() => ProgressPopup.IsOpen = true));
                story = PrepareShowStory();
                story.Begin();
            }

            private Storyboard PrepareShowStory()
            {
                Storyboard story = new Storyboard();
                DoubleAnimation animation;

                animation = new DoubleAnimation();
                animation.From = 0;
                animation.To = 100;
                animation.Duration = new Duration(TimeSpan.FromMilliseconds(1000));
                Storyboard.SetTarget(animation, image1);
                //Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.Opacity)"));
                Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.Height)"));
                story.Children.Add(animation);

                story.AutoReverse = true;
                story.RepeatBehavior = new RepeatBehavior(3); //RepeatBehavior.Forever;

                return story;
            }
        }
  • 相关阅读:
    legend2---开发日志12(vue如何进一步学习)
    为什么现在的年轻人生育的欲望越来越低?(转自知乎)
    legend2---开发日志13(layer_mobile的content传入dom 出现【object object】如何解决)
    legend2---项目总结(legend2的意义)
    legend2---开发日志11(如何提高终极开发效率)
    公司项目架构的演变过程(转)
    创业公司如何实施敏捷开发(敏捷开发简单流程)(转)
    创业公司一年工作总结(转)(公司失败原因)
    LayaAir引擎开发HTML5最简单教程(面向JS开发者)
    [ACM] HDU 2295 Radar (二分法+DLX 重复覆盖)
  • 原文地址:https://www.cnblogs.com/zziss/p/2766522.html
Copyright © 2011-2022 走看看