zoukankan      html  css  js  c++  java
  • WPF 过渡效果

    http://blog.csdn.net/lhx527099095/article/details/8005095


    先上张效果图看看 如果不如您的法眼 可以移步了 或者有更好的效果 可以留言给我 



    废话不多说 直接贴代码 一个usercontrol

    [csharp] view plaincopy
    1. <UserControl x:Class="LoadingMask_Demo.LoadingWait"  
    2.              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
    3.              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
    4.              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"   
    5.              IsVisibleChanged="HandleVisibleChanged">  
    6.     <UserControl.Background>  
    7.         <SolidColorBrush Color="Black" Opacity="0.2"  />  
    8.     </UserControl.Background>  
    9.     <UserControl.Resources>  
    10.         <SolidColorBrush Color="#FF007BE5" x:Key="CirclesColor" />  
    11.         <!--<SolidColorBrush Color="Black" x:Key="BackgroundColor" Opacity=".20" />-->  
    12.     </UserControl.Resources>  
    13.   
    14.     <Viewbox Width="100" Height="100"    
    15.             HorizontalAlignment="Center"    
    16.             VerticalAlignment="Center">  
    17.         <Grid x:Name="LayoutRoot"     
    18.                 Background="Transparent"    
    19.                 ToolTip="Please wait...."    
    20.                 HorizontalAlignment="Center"    
    21.                 VerticalAlignment="Center">  
    22.             <TextBlock Text="Loading..."  HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="14" Foreground="#FFE3953D" FontWeight="Bold" />  
    23.             <Canvas RenderTransformOrigin="0.5,0.5"    
    24.                     HorizontalAlignment="Center"    
    25.                     VerticalAlignment="Center" Width="120"    
    26.                     Height="120" Loaded="HandleLoaded"    
    27.                     Unloaded="HandleUnloaded"  >  
    28.                 <Ellipse x:Name="C0" Width="20" Height="20"    
    29.                          Canvas.Left="0"    
    30.                          Canvas.Top="0" Stretch="Fill"    
    31.                          Fill="{StaticResource CirclesColor}" Opacity="1.0"/>  
    32.                 <Ellipse x:Name="C1" Width="20" Height="20"    
    33.                          Canvas.Left="0"    
    34.                          Canvas.Top="0" Stretch="Fill"    
    35.                          Fill="{StaticResource CirclesColor}" Opacity="0.9"/>  
    36.                 <Ellipse x:Name="C2" Width="20" Height="20"    
    37.                          Canvas.Left="0"    
    38.                          Canvas.Top="0" Stretch="Fill"    
    39.                          Fill="{StaticResource CirclesColor}" Opacity="0.8"/>  
    40.                 <Ellipse x:Name="C3" Width="20" Height="20"    
    41.                          Canvas.Left="0"    
    42.                          Canvas.Top="0" Stretch="Fill"    
    43.                          Fill="{StaticResource CirclesColor}" Opacity="0.7"/>  
    44.                 <Ellipse x:Name="C4" Width="20" Height="20"    
    45.                          Canvas.Left="0"    
    46.                          Canvas.Top="0" Stretch="Fill"    
    47.                          Fill="{StaticResource CirclesColor}" Opacity="0.6"/>  
    48.                 <Ellipse x:Name="C5" Width="20" Height="20"    
    49.                          Canvas.Left="0"    
    50.                          Canvas.Top="0" Stretch="Fill"    
    51.                          Fill="{StaticResource CirclesColor}" Opacity="0.5"/>  
    52.                 <Ellipse x:Name="C6" Width="20" Height="20"    
    53.                          Canvas.Left="0"    
    54.                          Canvas.Top="0" Stretch="Fill"    
    55.                          Fill="{StaticResource CirclesColor}" Opacity="0.4"/>  
    56.                 <Ellipse x:Name="C7" Width="20" Height="20"    
    57.                          Canvas.Left="0"    
    58.                          Canvas.Top="0" Stretch="Fill"    
    59.                          Fill="{StaticResource CirclesColor}" Opacity="0.3"/>  
    60.                 <Ellipse x:Name="C8" Width="20" Height="20"    
    61.                          Canvas.Left="0"    
    62.                          Canvas.Top="0" Stretch="Fill"    
    63.                          Fill="{StaticResource CirclesColor}" Opacity="0.2"/>  
    64.                 <Canvas.RenderTransform>  
    65.                     <RotateTransform x:Name="SpinnerRotate"    
    66.                          Angle="0" />  
    67.                 </Canvas.RenderTransform>  
    68.             </Canvas>  
    69.         </Grid>  
    70.     </Viewbox>  
    71. </UserControl>  
    72.   
    73.   
    74. 后台代码:  
    75.   
    76.   
    77. using System;  
    78. using System.Collections.Generic;  
    79. using System.Linq;  
    80. using System.Text;  
    81. using System.Windows;  
    82. using System.Windows.Controls;  
    83. using System.Windows.Data;  
    84. using System.Windows.Documents;  
    85. using System.Windows.Input;  
    86. using System.Windows.Media;  
    87. using System.Windows.Media.Imaging;  
    88. using System.Windows.Navigation;  
    89. using System.Windows.Shapes;  
    90. using System.Windows.Threading;  
    91.   
    92. namespace LoadingMask_Demo  
    93. {  
    94.     /// <summary>  
    95.     /// Interaction logic for LoadingWait.xaml  
    96.     /// </summary>  
    97.     public partial class LoadingWait : UserControl  
    98.     {  
    99.         #region Data  
    100.         private readonly DispatcherTimer animationTimer;  
    101.         #endregion  
    102.  
    103.         #region Constructor  
    104.         public LoadingWait()  
    105.         {  
    106.             InitializeComponent();  
    107.   
    108.             animationTimer = new DispatcherTimer(  
    109.                 DispatcherPriority.ContextIdle, Dispatcher);  
    110.             animationTimer.Interval = new TimeSpan(0, 0, 0, 0, 90);  
    111.         }  
    112.         #endregion  
    113.  
    114.         #region Private Methods  
    115.         private void Start()  
    116.         {  
    117.             animationTimer.Tick += HandleAnimationTick;  
    118.             animationTimer.Start();  
    119.         }  
    120.   
    121.         private void Stop()  
    122.         {  
    123.             animationTimer.Stop();  
    124.             animationTimer.Tick -= HandleAnimationTick;  
    125.         }  
    126.   
    127.         private void HandleAnimationTick(object sender, EventArgs e)  
    128.         {  
    129.             SpinnerRotate.Angle = (SpinnerRotate.Angle + 36) % 360;  
    130.         }  
    131.   
    132.         private void HandleLoaded(object sender, RoutedEventArgs e)  
    133.         {  
    134.             const double offset = Math.PI;  
    135.             const double step = Math.PI * 2 / 10.0;  
    136.   
    137.             SetPosition(C0, offset, 0.0, step);  
    138.             SetPosition(C1, offset, 1.0, step);  
    139.             SetPosition(C2, offset, 2.0, step);  
    140.             SetPosition(C3, offset, 3.0, step);  
    141.             SetPosition(C4, offset, 4.0, step);  
    142.             SetPosition(C5, offset, 5.0, step);  
    143.             SetPosition(C6, offset, 6.0, step);  
    144.             SetPosition(C7, offset, 7.0, step);  
    145.             SetPosition(C8, offset, 8.0, step);  
    146.         }  
    147.   
    148.         private void SetPosition(Ellipse ellipse, double offset,  
    149.             double posOffSet, double step)  
    150.         {  
    151.             ellipse.SetValue(Canvas.LeftProperty, 50.0  
    152.                 + Math.Sin(offset + posOffSet * step) * 50.0);  
    153.   
    154.             ellipse.SetValue(Canvas.TopProperty, 50  
    155.                 + Math.Cos(offset + posOffSet * step) * 50.0);  
    156.         }  
    157.   
    158.         private void HandleUnloaded(object sender, RoutedEventArgs e)  
    159.         {  
    160.             Stop();  
    161.         }  
    162.   
    163.         private void HandleVisibleChanged(object sender,  
    164.             DependencyPropertyChangedEventArgs e)  
    165.         {  
    166.             bool isVisible = (bool)e.NewValue;  
    167.   
    168.             if (isVisible)  
    169.                 Start();  
    170.             else  
    171.                 Stop();  
    172.         }  
    173.         #endregion    
    174.     }  
    175. }  

    调用的代码也贴出来吧


    [csharp] view plaincopy
    1. <Window x:Class="LoadingMask_Demo.MainWindow"  
    2.         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
    3.         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
    4.         Title="MainWindow" Height="350" Width="525"  
    5.         xmlns:local="clr-namespace:LoadingMask_Demo"  
    6.         >  
    7.     <DockPanel>  
    8.         <StackPanel Orientation="Horizontal" DockPanel.Dock="Top">  
    9.             <Button  Content="show" Width="70" Height="30" Click="ShowButton_Click" />  
    10.             <Button  Content="hide" Width="70" Height="30" Click="HideButton_Click"/>  
    11.         </StackPanel>  
    12.           
    13.         <Grid Background="#FF484848" DockPanel.Dock="Bottom">  
    14.             <TextBlock Text="asdfasdfasdf" Foreground="White"/>  
    15.             <local:LoadingWait x:Name="_loading"  Visibility="Collapsed"/>  
    16.         </Grid>  
    17.     </DockPanel>  
    18. </Window>  
    19.   
    20.   
    21. 后台代码  
    22.   
    23.   
    24. using System;  
    25. using System.Collections.Generic;  
    26. using System.Linq;  
    27. using System.Text;  
    28. using System.Windows;  
    29. using System.Windows.Controls;  
    30. using System.Windows.Data;  
    31. using System.Windows.Documents;  
    32. using System.Windows.Input;  
    33. using System.Windows.Media;  
    34. using System.Windows.Media.Imaging;  
    35. using System.Windows.Navigation;  
    36. using System.Windows.Shapes;  
    37.   
    38. namespace LoadingMask_Demo  
    39. {  
    40.     /// <summary>  
    41.     /// Interaction logic for MainWindow.xaml  
    42.     /// </summary>  
    43.     public partial class MainWindow : Window  
    44.     {  
    45.         public MainWindow()  
    46.         {  
    47.             InitializeComponent();  
    48.         }  
    49.   
    50.         private void ShowButton_Click(object sender, RoutedEventArgs e)  
    51.         {  
    52.             this._loading.Visibility = Visibility.Visible;  
    53.         }  
    54.   
    55.         private void HideButton_Click(object sender, RoutedEventArgs e)  
    56.         {  
    57.             this._loading.Visibility = Visibility.Collapsed;  
    58.         }  
    59.   
    60.     }  
    61. }  

  • 相关阅读:
    Hadoop--单点故障修复
    Hadoop---静动态增删节点
    sqlserver 通知应用程序(存储过程通过http调用接口)
    sqlserver 资源等待
    sqlserver 性能优化
    sqlserver 资源等待
    sqlserver 查看内存情况
    sqlserver动态管理视图
    常见散列算法
    sqlserver 性能检测 和 监控
  • 原文地址:https://www.cnblogs.com/swarb/p/9924271.html
Copyright © 2011-2022 走看看