XAML代码:
1 <Window x:Class="线性插值动画.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" Loaded="Window_Loaded" 5 > 6 <Grid> 7 <TextBlock Width="220" Height="50" Foreground="#326939" FontSize="36" Name="textBlock1" Text="文字渐变效果"/> 8 </Grid> 9 </Window>
.CS代码:
1 using System; 2 using System.Windows; 3 using System.Windows.Controls; 4 using System.Windows.Media.Animation; 5 namespace 线性插值动画 6 { 7 /// <summary> 8 /// MainWindow.xaml 的交互逻辑 9 /// </summary> 10 public partial class MainWindow : Window 11 { 12 public MainWindow() 13 { 14 InitializeComponent(); 15 } 16 17 private void Window_Loaded(object sender, System.Windows.RoutedEventArgs e) 18 { 19 // 在此处添加事件处理程序实现。 20 DoubleAnimation da=new DoubleAnimation(); 21 da.From=0; 22 da.To=1; 23 da.Duration=TimeSpan.FromSeconds(3); 24 this.textBlock1.BeginAnimation(TextBlock.OpacityProperty,da); 25 } 26 } 27 }
时间: 2024-11-09 08:48:13