2015-12-11 43 views
0

我想将文字突出显示为“滑动解锁”iPhone。 你能帮我吗? 谢谢!使用xaml或C#创建光动画

这样的

iPhone slide

+2

使用渐变。我没有使用iPhone的经验。难道你滑得越多,文字的部分就越白(er)? –

回答

3

的一种方法是使用一个LinearGradientBrush,然后动画的渐变色打造的“频闪”的效果。

下面是一个基本的窗口与一些文本的XAML是说明了该技术:

<Window x:Class="StackOverflow.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Background="Black"> 
    <TextBlock x:Name="_text" Text="Hello World" 
     FontSize="60" HorizontalAlignment="Center" VerticalAlignment="Center"> 
     <TextBlock.Foreground> 
      <LinearGradientBrush StartPoint="0,0" EndPoint="1,0" 
       ColorInterpolationMode="ScRgbLinearInterpolation"> 
       <GradientStop Color="#ff666666" Offset="-0.2" /> 
       <GradientStop Color="#ffffffff" Offset="-0.1" /> 
       <GradientStop Color="#ff666666" Offset="0" /> 
      </LinearGradientBrush> 
     </TextBlock.Foreground> 
     <TextBlock.Triggers> 
      <EventTrigger> 
       <BeginStoryboard> 
        <Storyboard RepeatBehavior="Forever" EnableDependentAnimation="True"> 
         <DoubleAnimation Storyboard.TargetName="_text" 
          Storyboard.TargetProperty="(TextBlock.Foreground).(GradientBrush.GradientStops)[0].(GradientStop.Offset)" 
          From="-0.2" To="1.5" Duration="0:0:1.5" /> 
         <DoubleAnimation Storyboard.TargetName="_text" 
          Storyboard.TargetProperty="(TextBlock.Foreground).(GradientBrush.GradientStops)[1].(GradientStop.Offset)" 
          From="-0.1" To="1.6" Duration="0:0:1.5" /> 
         <DoubleAnimation Storyboard.TargetName="_text" 
          Storyboard.TargetProperty="(TextBlock.Foreground).(GradientBrush.GradientStops)[2].(GradientStop.Offset)" 
          From="0" To="1.7" Duration="0:0:1.5" /> 
        </Storyboard> 
       </BeginStoryboard> 
      </EventTrigger> 
     </TextBlock.Triggers> 
    </TextBlock> 
</Window> 

您可以用渐变停止颜色和偏移实验,再加上DoubleAnimation是的持续时间元素,以获得你所追求的效果。请记住,所有三个动画元素的持续时间必须相同。

+0

谢谢史蒂夫!它在WPF上完美运行!但是,当我尝试在通用Windows上使用它时,它不起作用。请注意,我必须将RoutedEvent从“Loaded”更改为“TextBlock.Loaded”,但仍然不起作用。任何想法?谢谢... – Sam

+0

基于这个[MSDN页面](https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.eventtrigger.aspx)中的示例,它看起来像尽管Windows Universal应用程序不支持“RoutedEvent”属性。我在我的答案中编辑了代码示例。也许给一下去看看它是否解决了这个问题。 –

+0

我也根据我读的另一个[MSDN页面](https://msdn.microsoft.com/en-us/library/windows/apps/mt187354)稍微更改了'Storyboard.TargetProperty'路径。不幸的是,我无法测试这些代码更改,因为我目前无法编写Windows通用应用程序。 –