Joh*_*rth 5 silverlight wpf xaml
我正在寻找一种方法来为我正在研究的全屏WPF应用程序创建一个"看起来很酷"的效果 - 一种"屏幕闪烁"效果,可以在整个屏幕上激活或移动,从而发出闪亮的显示体验.我正在考虑创建一个带有突出显示渐变和透明背景的大矩形,可以在屏幕上进行动画制作.有任何想法如何在XAML中有效地完成这项工作?
我提出了一个看起来很不错的解决方案.我在Blend 2.0 SP1中编写的一些示例XAML如下所示:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="ScreenGlintApplication.Window1"
x:Name="Window"
Title="Window1"
Width="500" Height="250" Background="#FF000000" Foreground="#FF3EE229" >
<Grid x:Name="LayoutRoot">
<TextBlock TextWrapping="Wrap" FontSize="40" >
<Run Text="This is some sample text to have something to work with. Have a nice day! /Johan"/>
</TextBlock>
<Canvas Panel.ZIndex="99" >
<Rectangle x:Name="ScreenGlintRect"
Width="{Binding Path=ActualWidth, ElementName=Window, Mode=Default}"
Height="{Binding Path=ActualHeight, ElementName=Window, Mode=Default}"
Opacity="0.4" >
<Rectangle.Triggers>
<EventTrigger RoutedEvent="Rectangle.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="ScreenGlintRect"
Storyboard.TargetProperty="(Canvas.Left)"
From="-500" To="1000" Duration="0:0:2" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Rectangle.Triggers>
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,1" EndPoint="1,1">
<GradientStop Color="Transparent" Offset="0.0" />
<GradientStop x:Name="GlintColor" Color="LightGreen" Offset="0.50" />
<GradientStop Color="Transparent" Offset="1" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Canvas>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
一个选项是在后面的代码中执行此操作,如果您想要对动画进行精细控制,这非常简洁.例如:
ScreenGlintRect.Width = Width;
ScreenGlintRect.Height = Height;
var animation = new DoubleAnimation
{
Duration = new Duration(TimeSpan.FromSeconds(2)),
From = (-Width),
To = Width * 2
};
ScreenGlintRect.BeginAnimation(Canvas.LeftProperty, animation);
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的代码,它对我来说看起来不错.如果你有硬件加速,你可以尝试添加一些模糊.您可能需要调整代码并隐藏/显示矩形,但基本上就是这样.
归档时间: |
|
查看次数: |
3448 次 |
最近记录: |