1
WPF的新手。簡單的場景。無法找出正確的方法來做到這一點。WPF - 動畫問題
說我有一個單一的按鈕。我也有四個TextBlocks。我想要一個按鈕同時觸發所有TextBlock上的動畫(不透明度從0到1)。
在此先感謝!
WPF的新手。簡單的場景。無法找出正確的方法來做到這一點。WPF - 動畫問題
說我有一個單一的按鈕。我也有四個TextBlocks。我想要一個按鈕同時觸發所有TextBlock上的動畫(不透明度從0到1)。
在此先感謝!
這應該這樣做...
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication1.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Window.Resources>
<Storyboard x:Key="OnClick1">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="textBlock" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="textBlock1" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="textBlock2" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="textBlock3" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent="ButtonBase.Click" SourceName="button">
<BeginStoryboard Storyboard="{StaticResource OnClick1}"/>
</EventTrigger>
</Window.Triggers>
<Grid x:Name="LayoutRoot">
<StackPanel>
<Button x:Name="button" Width="131" Height="37" Content="Button" Margin="0,0,0,22"/>
<TextBlock x:Name="textBlock" Height="27" Text="TextBlock 1" TextWrapping="Wrap" Opacity="0"/>
<TextBlock x:Name="textBlock1" Height="27" Text="TextBlock 2" TextWrapping="Wrap" Opacity="0"/>
<TextBlock x:Name="textBlock2" Height="27" Text="TextBlock 3" TextWrapping="Wrap" Opacity="0"/>
<TextBlock x:Name="textBlock3" Height="27" Text="TextBlock 4" TextWrapping="Wrap" Opacity="0"/>
</StackPanel>
</Grid>
</Window>
只是要看到作爲一個不錯的選擇,看my answer到類似的問題。
難道還有更好的辦法嗎?我對動畫不是很有經驗,但是重複同樣的東西4次似乎是錯誤的... – 2009-08-06 13:30:58
謝謝,謝謝,謝謝......現在,只是想深入一點,如果我有一個塊的X TextBlocks,在網格列中說。我怎樣才能將Storyboard分配給該網格中的所有TextBlocks,而無需分別爲每個動畫分配一個動畫? – LSTayon 2009-08-06 13:40:16
是的托馬斯,這就是我所說的...... – LSTayon 2009-08-06 13:40:51