1
我有一個按鈕,單擊時會將更多數據加載到數據網格中。爲了顯示進度,我將按鈕的文本從「更多」更改爲動畫期間的「正在加載...」。接下來,我想添加一個「閃爍」效果,使文字吸引你的目光。如果您使用過iPhone/iPod Touch,我正在考慮對鎖定屏幕的「幻燈片解鎖」文本的影響。在動畫文本上設置動畫文字閃爍
爲此,我將一箇中間較輕的漸變止動從左向右移動。由於動畫不斷循環,因此我使用有效範圍外的偏移來創建光梯度停止實際可見時的時間間隔。
我得到了這個實現,但我可以告訴,由於某種原因,光梯度不是從文本的左邊緣開始。它始於「加載」中的'a'。我接受了這一點,並且已經存在了一段時間,但我現在回過頭來試圖理解爲什麼。它似乎也許是在計算動畫時使用原始文本的度量,但我認爲動畫在相同的情節提要中應該適用於彼此。這裏是我的代碼:
<UserControl.Resources>
<local:EmptyBatchNumConverter x:Key="emptyBatchNumConverter" />
<BeginStoryboard x:Key="bsbLoadingMore" x:Name="bsbLoadingMore">
<Storyboard x:Name="sbLoadingMore">
<StringAnimationUsingKeyFrames Storyboard.TargetName="txtBtnMoreText" Storyboard.TargetProperty="Text" Duration="0:0:2" FillBehavior="Stop" RepeatBehavior="Forever">
<DiscreteStringKeyFrame Value="Loading" KeyTime="0:0:0" />
<DiscreteStringKeyFrame Value="Loading." KeyTime="0:0:0.5" />
<DiscreteStringKeyFrame Value="Loading.." KeyTime="0:0:1" />
<DiscreteStringKeyFrame Value="Loading..." KeyTime="0:0:1.5" />
</StringAnimationUsingKeyFrames>
<!--Animate the OffSet of the light gradient stop for a "glint" effect. Using -4.5 to 4.5 to delay the visible effect between repeats (and
control the speed relative to the duration). Using an extra .4 seconds to offset the frequency from the text animation. -->
<DoubleAnimation Storyboard.TargetName="gs2" Storyboard.TargetProperty="Offset" From="-4.5" To="4.5" Duration="0:0:2.4" RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</UserControl.Resources>
...
<Button Name="btnMore" Grid.Row="1" Style="{StaticResource OasisGridMoreButton}" Click="btnMore_Click" Visibility="Visible" Height="16">
<Button.Content>
<TextBlock Name="txtBtnMoreText" MinWidth="48" Text="More..." /> <!--MinWidth = width of "Loading..."-->
</Button.Content>
<Button.Foreground>
<LinearGradientBrush StartPoint="0.2,0" EndPoint="1,1">
<GradientStop x:Name="gs1" Color="Black" Offset="0"/>
<GradientStop x:Name="gs2" Color="Cyan" Offset="-4.5"/>
<GradientStop x:Name="gs3" Color="Black" Offset="1" />
</LinearGradientBrush>
</Button.Foreground>
</Button>
哇。你知道他們說什麼,「問一個愚蠢的問題,看起來很愚蠢。」如果可以,我會自己。謝謝。 這解決了這個問題,確實夠好,但並不完全符合我的要求。當gs2的偏移量爲<1時,文本全部爲黑色。直到它> = 0時纔會變得可見。當它= 0時,文本的左側完全是青色。所以漸變的漸變右側永遠不會「越過」「L」。它只是瞬間變成青色。無論如何,梯度完全從左側進入並移過右側? – xr280xr 2012-02-08 19:32:17