2
我一直在關注如何製作標籤閃存的一些說明。我沒有很多動畫經驗,所以我不知道我的問題在哪裏!我的代碼是:WPF故事板動畫不閃爍
<Window x:Class="WPFAnimationStoryBoard.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WPFAnimationStoryBoard"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<ResourceDictionary>
<Storyboard x:Key="blinkAnimation" RepeatBehavior="1" >
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)"
Storyboard.TargetName="InitProc"
AutoReverse="True">
<ColorAnimationUsingKeyFrames.KeyFrames>
<DiscreteColorKeyFrame KeyTime="0:0:0" Value="White"/>
<DiscreteColorKeyFrame KeyTime="0:0:1" Value="Black"/>
<DiscreteColorKeyFrame KeyTime="0:0:2" Value="White"/>
<DiscreteColorKeyFrame KeyTime="0:0:3" Value="Black"/>
<DiscreteColorKeyFrame KeyTime="0:0:4" Value="White"/>
</ColorAnimationUsingKeyFrames.KeyFrames>
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Foreground).(SolidColorBrush.Color)"
Storyboard.TargetName="InitProc"
AutoReverse="True">
<ColorAnimationUsingKeyFrames.KeyFrames>
<DiscreteColorKeyFrame KeyTime="0:0:0" Value="Black"/>
<DiscreteColorKeyFrame KeyTime="0:0:1" Value="White"/>
<DiscreteColorKeyFrame KeyTime="0:0:2" Value="Black"/>
<DiscreteColorKeyFrame KeyTime="0:0:3" Value="White"/>
<DiscreteColorKeyFrame KeyTime="0:0:4" Value="Black"/>
</ColorAnimationUsingKeyFrames.KeyFrames>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</ResourceDictionary>
</Window.Resources>
<Grid>
<Label Name="InitProc" Grid.Row="0" Grid.Column="2" Content="{Binding ElementName=myWindow, Path=Hello}" Background="White" Foreground="Black">
<Label.Triggers>
<EventTrigger RoutedEvent="Binding.TargetUpdated">
<EventTrigger.Actions>
<BeginStoryboard>
<StaticResource ResourceKey="blinkAnimation"/>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Label.Triggers>
</Label>
</Grid>
這裏是我的代碼背後:
namespace WPFAnimationStoryBoard
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window, INotifyPropertyChanged
{
public MainWindow()
{
InitializeComponent();
Hello = "hello";
}
private string _hello;
public event PropertyChangedEventHandler PropertyChanged;
public string Hello
{
get { return _hello; }
set
{
_hello = value;
OnPropertyChanged("Hello");
}
}
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
}
}
我在做什麼錯誤?如果能和答案一起提供一些動畫背後的內容,我將不勝感激。
謝謝!
編輯:我改變了允許綁定屬性更新...丟棄了那個球。它仍然不會產生閃爍,但它確實在用戶界面中顯示世界「你好」。
當你期望閃爍的發生呢?對任何Label的屬性都沒有綁定,所以Binding.TargetUpdated事件可能永遠不會被觸發。 – Clemens
Touchee ....我應該看到的! – Maderas
你美麗漂亮的人你!發佈答案,以便我可以接受! – Maderas