1 using System; 2 using System.Collections.Generic; 3 using System.IO; 4 using System.Linq; 5 using System.Runtime.InteropServices.WindowsRuntime; 6 using System.Threading.Tasks; 7 using Windows.Foundation; 8 using Windows.Foundation.Collections; 9 using Windows.UI.Xaml; 10 using Windows.UI.Xaml.Controls; 11 using Windows.UI.Xaml.Controls.Primitives; 12 using Windows.UI.Xaml.Data; 13 using Windows.UI.Xaml.Input; 14 using Windows.UI.Xaml.Media; 15 using Windows.UI.Xaml.Navigation; 16 17 // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 18 19 namespace RainbowEight 20 { 21 /// <summary> 22 /// An empty page that can be used on its own or navigated to within a Frame. 23 /// </summary> 24 public sealed partial class MainPage : Page 25 { 26 double txtblkBaseSize; 27 Random rand = new Random(); 28 public MainPage() 29 { 30 this.InitializeComponent(); 31 Loaded += OnPageLoad; 32 } 33 34 void OnPageLoad(object sender,RoutedEventArgs e) 35 { 36 txtblkBaseSize = txtblk.ActualHeight; 37 CompositionTarget.Rendering += OnCompositionTargetRendering; 38 } 39 40 void OnCompositionTargetRendering(object sender,object e) 41 { 42 // TimeSpan.FromSeconds(30000) 43 // Task.Delay(30); 44 // Sleep(1000); 45 46 // txtblk.Text = (rand.Next() % 10).ToString(); 47 48 txtblk.FontSize = ActualHeight / txtblkBaseSize; 49 50 RenderingEventArgs renderingArgs = e as RenderingEventArgs; 51 52 double t = (0.25 * renderingArgs.RenderingTime.TotalSeconds) % 1; 53 54 for (int index=0; index < gradientBrush.GradientStops.Count; index++) 55 { 56 gradientBrush.GradientStops[index].Offset = index / 7.0 - t; 57 } 58 } 59 60 static void Sleep(int ms) 61 { 62 new System.Threading.ManualResetEvent(false).WaitOne(ms); 63 } 64 65 private void OnPage_SizeChanged(object sender, SizeChangedEventArgs e) 66 { 67 txtblkBaseSize = txtblk.ActualHeight; 68 // 69 // txtblk.FontSize = 8; 70 txtblk.FontSize = ActualHeight / txtblkBaseSize; 71 } 72 } 73 }
1 <Page 2 x:Class="RainbowEight.MainPage" 3 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 4 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 5 xmlns:local="using:RainbowEight" 6 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 7 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 8 mc:Ignorable="d"> 9 10 <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 11 <TextBlock Name="txtblk" 12 Text="8" 13 FontFamily="CooperBlack" 14 FontSize="1" 15 HorizontalAlignment="Center" 16 > 17 <TextBlock.Foreground> 18 <LinearGradientBrush x:Name="gradientBrush"> 19 <GradientStop Offset="0.00" Color="Red"/> 20 <GradientStop Offset="0.14" Color="Orange"/> 21 <GradientStop Offset="0.28" Color="Yellow"/> 22 <GradientStop Offset="0.43" Color="Green"/> 23 <GradientStop Offset="0.57" Color="Blue"/> 24 <GradientStop Offset="0.71" Color="Indigo"/> 25 <GradientStop Offset="0.86" Color="Violet"/> 26 <GradientStop Offset="1.00" Color="Red"/> 27 <GradientStop Offset="1.14" Color="Orange"/> 28 <GradientStop Offset="1.28" Color="Yellow"/> 29 <GradientStop Offset="1.43" Color="Green"/> 30 <GradientStop Offset="1.57" Color="Blue"/> 31 <GradientStop Offset="1.71" Color="Indigo"/> 32 <GradientStop Offset="1.86" Color="Violet"/> 33 <GradientStop Offset="2.00" Color="Red"/> 34 </LinearGradientBrush> 35 </TextBlock.Foreground> 36 </TextBlock> 37 </Grid> 38 </Page>