背水一戰 Windows 10 之 動畫: PopInThemeAnimation - 控制項出現時的動畫, PopOutThemeAnimation - 控制項消失時的動畫, FadeInThemeAnimation - 控制項淡入的動畫, FadeOutThemeAnimation - 控制項淡出的動畫... ...
背水一戰 Windows 10 (16) - 動畫: ThemeAnimation(主題動畫)
作者:webabcd
介紹
背水一戰 Windows 10 之 動畫
- PopInThemeAnimation - 控制項出現時的動畫
- PopOutThemeAnimation - 控制項消失時的動畫
- FadeInThemeAnimation - 控制項淡入的動畫
- FadeOutThemeAnimation - 控制項淡出的動畫
- PointerDownThemeAnimation - 滑鼠(手指)在控制項上按下時的動畫
- PointerUpThemeAnimation - 滑鼠(手指)在控制項上抬起時的動畫
- SwipeHintThemeAnimation - 控制項的 Swipe 動畫(當你的控制項在收到 Swipe 後會做響應時)
- SwipeBackThemeAnimation - 控制項的 Swipe 動畫(當你的控制項在收到 Swipe 後不需要做任何響應時)
- RepositionThemeAnimation - 控制項重新定位時的動畫
- SplitOpenThemeAnimation - 打開“拆分”控制項的動畫
- SplitCloseThemeAnimation - 關閉“拆分”控制項的動畫
- DragItemThemeAnimation, DragOverThemeAnimation, DropTargetItemThemeAnimation - 顧名思義的一些動畫效果,用於集合類的控制項
示例
1、演示主題動畫之 PopIn, PopOut
Animation/ThemeAnimation/PopInPopOut.xaml
<Page x:Class="Windows10.Animation.ThemeAnimation.PopInPopOut" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Windows10.Animation.ThemeAnimation" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <Grid Background="Transparent"> <StackPanel Margin="10 0 10 10"> <StackPanel.Resources> <!-- 註:各種 ThemeAnimation 均繼承自 Timeline,但是 Timeline 的相關的控制類屬性均無效,因為各種控制類屬性是由對應的 ThemeAnimation 來決定的 --> <!-- PopInThemeAnimation - 控制項出現時的動畫 FromHorizontalOffset - 控制項起始位置的水平偏移量 FromVerticalOffset - 控制項起始位置的垂直偏移量 --> <Storyboard x:Name="storyboardPopIn"> <PopInThemeAnimation Storyboard.TargetName="border" FromHorizontalOffset="1000" FromVerticalOffset="300" /> </Storyboard> <!-- PopOutThemeAnimation - 控制項消失時的動畫 --> <Storyboard x:Name="storyboardPopOut"> <PopOutThemeAnimation Storyboard.TargetName="border" /> </Storyboard> </StackPanel.Resources> <Border Name="border" BorderThickness="5" BorderBrush="Red" Background="Blue" CornerRadius="10" Width="400" Height="100" HorizontalAlignment="Left"> <Border.Child> <TextBlock Text="我是 Border 里的內容" TextAlignment="Center" VerticalAlignment="Center" /> </Border.Child> </Border> <Button Name="btnPopIn" Content="PopInThemeAnimation Demo" Click="btnPopIn_Click" Margin="0 30 0 0" /> <Button Name="btnPopOut" Content="PopOutThemeAnimation Demo" Click="btnPopOut_Click" Margin="0 10 0 0" /> </StackPanel> </Grid> </Page>
Animation/ThemeAnimation/PopInPopOut.xaml.cs
/* * PopInThemeAnimation - 控制項出現時的動畫 * PopOutThemeAnimation - 控制項消失時的動畫 */ using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; namespace Windows10.Animation.ThemeAnimation { public sealed partial class PopInPopOut : Page { public PopInPopOut() { this.InitializeComponent(); } private void btnPopIn_Click(object sender, RoutedEventArgs e) { storyboardPopIn.Begin(); } private void btnPopOut_Click(object sender, RoutedEventArgs e) { storyboardPopOut.Begin(); } } }
2、演示主題動畫之 FadeIn, FadeOut
Animation/ThemeAnimation/FadeInFadeOut.xaml
<Page x:Class="Windows10.Animation.ThemeAnimation.FadeInFadeOut" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Windows10.Animation.ThemeAnimation" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <Grid Background="Transparent"> <StackPanel Margin="10 0 10 10"> <StackPanel.Resources> <!-- 註:各種 ThemeAnimation 均繼承自 Timeline,但是 Timeline 的相關的控制類屬性均無效,因為各種控制類屬性是由對應的 ThemeAnimation 來決定的 --> <!-- FadeInThemeAnimation - 控制項淡入的動畫 --> <Storyboard x:Name="storyboardFadeIn"> <FadeInThemeAnimation Storyboard.TargetName="border" Duration="00:00:10" /> </Storyboard> <!-- FadeOutThemeAnimation - 控制項淡出的動畫 --> <Storyboard x:Name="storyboardFadeOut"> <FadeOutThemeAnimation Storyboard.TargetName="border" Duration="00:00:10" /> </Storyboard> </StackPanel.Resources> <Border Name="border" BorderThickness="5" BorderBrush="Red" Background="Blue" CornerRadius="10" Width="400" Height="100" HorizontalAlignment="Left"> <Border.Child> <TextBlock Text="我是 Border 里的內容" TextAlignment="Center" VerticalAlignment="Center" /> </Border.Child> </Border> <Button Name="btnFadeIn" Content="FadeInThemeAnimation Demo" Click="btnFadeIn_Click" Margin="0 10 0 0" /> <Button Name="btnFadeOut" Content="FadeOutThemeAnimation Demo" Click="btnFadeOut_Click" Margin="0 10 0 0" /> </StackPanel> </Grid> </Page>
Animation/ThemeAnimation/FadeInFadeOut.xaml.cs
/* * FadeInThemeAnimation - 控制項淡入的動畫 * FadeOutThemeAnimation - 控制項淡出的動畫 */ using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; namespace Windows10.Animation.ThemeAnimation { public sealed partial class FadeInFadeOut : Page { public FadeInFadeOut() { this.InitializeComponent(); } private void btnFadeIn_Click(object sender, RoutedEventArgs e) { storyboardFadeIn.Begin(); } private void btnFadeOut_Click(object sender, RoutedEventArgs e) { storyboardFadeOut.Begin(); } } }
3、演示主題動畫之 PointerDown, PointerUp
Animation/ThemeAnimation/PointerDownPointerUp.xaml
<Page x:Class="Windows10.Animation.ThemeAnimation.PointerDownPointerUp" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Windows10.Animation.ThemeAnimation" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <Grid Background="Transparent"> <StackPanel Margin="10 0 10 10"> <StackPanel.Resources> <!-- 註:各種 ThemeAnimation 均繼承自 Timeline,但是 Timeline 的相關的控制類屬性均無效,因為各種控制類屬性是由對應的 ThemeAnimation 來決定的 --> <!-- PointerDownThemeAnimation - 滑鼠(手指)在控制項上按下時的動畫 --> <Storyboard x:Name="storyboardPointerDown"> <PointerDownThemeAnimation Storyboard.TargetName="border" /> </Storyboard> <!-- PointerUpThemeAnimation - 滑鼠(手指)在控制項上抬起時的動畫 --> <Storyboard x:Name="storyboardPointerUp"> <PointerUpThemeAnimation Storyboard.TargetName="border" /> </Storyboard> </StackPanel.Resources> <Border Name="border" BorderThickness="5" BorderBrush="Red" Background="Blue" CornerRadius="10" Width="400" Height="100" HorizontalAlignment="Left"> <Border.Child> <TextBlock Text="我是 Border 里的內容" TextAlignment="Center" VerticalAlignment="Center" /> </Border.Child> </Border> <Button Name="btnPointerDown" Content="PointerDownThemeAnimation Demo" Click="btnPointerDown_Click" Margin="0 10 0 0" /> <Button Name="btnPointerUp" Content="PointerUpThemeAnimation Demo" Click="btnPointerUp_Click" Margin="0 10 0 0" /> </StackPanel> </Grid> </Page>
Animation/ThemeAnimation/PointerDownPointerUp.xaml.cs
/* * PointerDownThemeAnimation - 滑鼠(手指)在控制項上按下時的動畫 * PointerUpThemeAnimation - 滑鼠(手指)在控制項上抬起時的動畫 */ using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; namespace Windows10.Animation.ThemeAnimation { public sealed partial class PointerDownPointerUp : Page { public PointerDownPointerUp() { this.InitializeComponent(); } private void btnPointerDown_Click(object sender, RoutedEventArgs e) { storyboardPointerDown.Begin(); } private void btnPointerUp_Click(object sender, RoutedEventArgs e) { storyboardPointerUp.Begin(); } } }
4、演示主題動畫之 SwipeHint, SwipeBack
Animation/ThemeAnimation/SwipeHintSwipeBack.xaml
<Page x:Class="Windows10.Animation.ThemeAnimation.SwipeHintSwipeBack" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Windows10.Animation.ThemeAnimation" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <Grid Background="Transparent"> <StackPanel Margin="10 0 10 10"> <StackPanel.Resources> <!-- 註:各種 ThemeAnimation 均繼承自 Timeline,但是 Timeline 的相關的控制類屬性均無效,因為各種控制類屬性是由對應的 ThemeAnimation 來決定的 --> <!-- SwipeHintThemeAnimation - 控制項的 Swipe 動畫(當你的控制項在收到 Swipe 後會做響應時) ToHorizontalOffset, ToVerticalOffset - 控制項需要到達的偏移量 --> <Storyboard x:Name="storyboardSwipeHint"> <SwipeHintThemeAnimation Storyboard.TargetName="border" ToHorizontalOffset="100" ToVerticalOffset="100" /> </Storyboard> <!-- SwipeBackThemeAnimation - 控制項的 Swipe 動畫(當你的控制項在收到 Swipe 後不需要做任何響應時) FromHorizontalOffset, FromVerticalOffset - 控制項從此偏移量返回原位 --> <Storyboard x:Name="storyboardSwipeBack"> <SwipeBackThemeAnimation Storyboard.TargetName="border" FromHorizontalOffset="100" FromVerticalOffset="100" /> </Storyboard> </StackPanel.Resources> <Border Name="border" BorderThickness="5" BorderBrush="Red" Background="Blue" CornerRadius="10" Width="400" Height="100" HorizontalAlignment="Left"> <Border.Child> <TextBlock Text="我是 Border 里的內容" TextAlignment="Center" VerticalAlignment="Center" /> </Border.Child> </Border> <Button Name="btnSwipeHint" Content="SwipeHintThemeAnimation Demo" Click="btnSwipeHint_Click" Margin="0 10 0 0" /> <Button Name="btnSwipeBack" Content="SwipeBackThemeAnimation Demo" Click="btnSwipeBack_Click" Margin="0 10 0 0" /> </StackPanel> </Grid> </Page>
Animation/ThemeAnimation/SwipeHintSwipeBack.xaml.cs
/* * SwipeHintThemeAnimation - 控制項的 Swipe 動畫(當你的控制項在收到 Swipe 後會做響應時) * SwipeBackThemeAnimation - 控制項的 Swipe 動畫(當你的控制項在收到 Swipe 後不需要做任何響應時) */ using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; namespace Windows10.Animation.ThemeAnimation { public sealed partial class SwipeHintSwipeBack : Page { public SwipeHintSwipeBack() { this.InitializeComponent(); } private void btnSwipeHint_Click(object sender, RoutedEventArgs e) { storyboardSwipeHint.Begin(); } private void btnSwipeBack_Click(object sender, RoutedEventArgs e) { storyboardSwipeBack.Begin(); } } }
5、演示主題動畫之 Reposition
Animation/ThemeAnimation/Reposition.xaml
<Page x:Class="Windows10.Animation.ThemeAnimation.Reposition" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Windows10.Animation.ThemeAnimation" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <Grid Background="Transparent"> <StackPanel Margin="10 0 10 10"> <StackPanel.Resources> <!-- 註:各種 ThemeAnimation 均繼承自 Timeline,但是 Timeline 的相關的控制類屬性均無效,因為各種控制類屬性是由對應的 ThemeAnimation 來決定的 --> <!-- RepositionThemeAnimation - 控制項重新定位時的動畫 FromHorizontalOffset, FromVerticalOffset - 控制項從此偏移量的位置重新定位到新的位置 --> <Storyboard x:Name="storyboardReposition"> <RepositionThemeAnimation Storyboard.TargetName="border" FromHorizontalOffset="1000" FromVerticalOffset="300" /> </Storyboard> </StackPanel.Resources> <Border Name="border" BorderThickness="5" BorderBrush="Red" Background="Blue" CornerRadius="10" Width="400" Height="100" HorizontalAlignment="Left"> <Border.Child> <TextBlock Text="我是 Border 里的內容" TextAlignment="Center" VerticalAlignment="Center" /> </Border.Child> </Border> <Button Name="btnReposition" Content="RepositionThemeAnimation Demo" Click="btnReposition_Click" Margin="0 10 0 0" /> </StackPanel> </Grid> </Page>
Animation/ThemeAnimation/Reposition.xaml.cs
/* * RepositionThemeAnimation - 控制項重新定位時的動畫 */ using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; namespace Windows10.Animation.ThemeAnimation { public sealed partial class Reposition : Page { public Reposition() { this.InitializeComponent(); } private void btnReposition_Click(object sender, RoutedEventArgs e) { storyboardReposition.Begin(); } } }
6、演示主題動畫之 SplitOpen, SplitClose
Animation/ThemeAnimation/SplitOpenSplitClose.xaml
<Page x:Class="Windows10.Animation.ThemeAnimation.SplitOpenSplitClose" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Windows10.Animation.ThemeAnimation" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <Grid Background="Transparent"> <StackPanel Margin="10 0 10 10"> <StackPanel.Resources> <!-- 註:各種 ThemeAnimation 均繼承自 Timeline,但是 Timeline 的相關的控制類屬性均無效,因為各種控制類屬性是由對應的 ThemeAnimation 來決定的 --> <!-- SplitOpenThemeAnimation - 打開“拆分”控制項的動畫 打開 OpenedTargetName(OpenedTargetName 的內容是 ContentTargetName),關閉 ClosedTargetName 具體的用法參見 ComboBox 的 ControlTemplate --> <Storyboard x:Name="storyboardSplitOpen"> <SplitOpenThemeAnimation OpenedTargetName="border" ContentTargetName="textBlock" ClosedTargetName="rectangle" ContentTranslationDirection="Left" ContentTranslationOffset="200" OffsetFromCenter="0" OpenedLength="1" ClosedLength="0" /> </Storyboard> <!-- SplitCloseThemeAnimation - 關閉“拆分”控制項的動畫 關閉 OpenedTargetName(OpenedTargetName 的內容是 ContentTargetName),打開 ClosedTargetName 具體的用法參見 ComboBox 的 ControlTemplate --> <Storyboard x:Name="storyboardSplitClose"> <SplitCloseThemeAnimation OpenedTargetName="border" ContentTargetName="textBlock" ClosedTargetName="rectangle" ContentTranslationDirection="Left" ContentTranslationOffset="200" OffsetFromCenter="0" OpenedLength="1" ClosedLength="0" /> </Storyboard> </StackPanel.Resources> <Rectangle Name="rectangle" Width="400" Height="100" Fill="Orange" HorizontalAlignment="Left" /> <Border Name="border" BorderThickness="5" BorderBrush="Red" Background="Blue" CornerRadius="10" Width="400" Height="100" HorizontalAlignment="Left" /> <Button Name="btnSplitOpen" Content="SplitOpenThemeAnimation Demo" Click="btnSplitOpen_Click" Margin="0 10 0 0" /> <Button Name="btnSplitClose" Content="SplitCloseThemeAnimation Demo" Click="btnSplitClose_Click" Margin="0 10 0 0" /> </StackPanel> </Grid> </Page>
Animation/ThemeAnimation/SplitOpenSplitClose.xaml.cs
/* * SplitOpenThemeAnimation - 打開“拆分”控制項的動畫 * SplitCloseThemeAnimation - 關閉“拆分”控制項的動畫 */ using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; namespace Windows10.Animation.ThemeAnimation { public sealed partial class SplitOpenSplitClose : Page { public SplitOpenSplitClose() { this.InitializeComponent(); } private void btnSplitOpen_Click(object sender, RoutedEventArgs e) { TextBlock textBlock = new TextBlock(); textBlock.Name = "textBlock"; textBlock.Text = "我是 Border 里的內容"; textBlock.TextAlignment = TextAlignment.Center; textBlock.VerticalAlignment = VerticalAlignment.Center; border.Child = textBlock; storyboardSplitOpen.Begin(); } private void btnSplitClose_Click(object sender, RoutedEventArgs e) { storyboardSplitClose.Begin(); } } }
7、演示主題動畫之 DragItem, DragOver, DropTargetItem
Animation/ThemeAnimation/DragItemDragOverDropTargetItem.xaml
<Page x:Class="Windows10.Animation.ThemeAnimation.DragItemDragOverDropTargetItem" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Windows10.Animation.ThemeAnimation" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <Grid Background="Transparent"> <StackPanel Margin="10 0 10 10"> <TextBlock LineHeight="22"> <Run>顧名思義的 DragItemThemeAnimation, DragOverThemeAnimation, DropTargetItemThemeAnimation</Run> <LineBreak /> <Run>具體的用法參見 GridViewItem 或 ListViewItem 的 ControlTemplate(另外,關於 GridViewItem 或 ListViewItem 的拖動項的說明,請參見控制項部分的對應的示例代碼)</Run> </TextBlock> </StackPanel> </Grid> </Page>
OK
[源碼下載]