• 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;
            }
        }
  • 相关阅读:
    Asp.Net Core中Session使用
    服务器开发- 牌和牌的基本操作
    服务器开发- Asp.Net Core中的websocket,并封装一个简单的中间件
    Lua Table转C# Dictionary
    Asp.Net Core 2.1+的视图缓存(响应缓存)
    C#中await和async关键字的简单理解
    SQLSERVER中分割字符串成多列
    Asp.Net Core Identity+EFCore + Mysql踩坑记录
    小试牛刀2:JavaScript基础题
    CSS典型案例实践
  • 原文地址:https://www.cnblogs.com/zziss/p/2766522.html
Copyright © 2020-2023  润新知