我試圖讓ContentControl
施加ContentThemeTransition
其中的內容將是一個字符串,所以當通過結合新路線的動畫。我也無法使用ContentThemeTransition
字符串變化一個TextBlock
,因爲這不是從ContentControl
派生。UWP ContentControl中不適用ContentThemeTransition
下面是一些示例XAML,顯示該問題。如果我編輯文本框中的文本(代表我的ViewModel中的ContentControl
真的綁定的文本),我希望ContentControl
中顯示的文本具有動畫效果,但不會。
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBox Grid.Row="0" x:Name="text" Text="Hello" Width="100" Height="30"/>
<ContentControl Grid.Row="1" Width="100" Height="100" Content="{Binding ElementName=text , Path=Text}">
<ContentControl.Transitions>
<TransitionCollection>
<ContentThemeTransition HorizontalOffset="40"/>
</TransitionCollection>
</ContentControl.Transitions>
</ContentControl>
</Grid>
我在做什麼錯?
非常感謝您的任何幫助。
更新:
好吧,現在到了某個地方。如果您將ContentControl
XAML更換爲
<ContentPresenter Background="Black" Foreground="Red" Grid.Row="1" Width="100" Height="100" Content="{Binding ElementName=text , Path=Text}">
<ContentPresenter.ContentTransitions>
<TransitionCollection>
<ContentThemeTransition VerticalOffset="-100"/>
</TransitionCollection>
</ContentPresenter.ContentTransitions>
</ContentPresenter>
然後它可以工作。奇怪的是,在上述VerticalOffset = -100的情況下,新值在ContentControl
之外動畫下來,即其在控制範圍外可見。任何人都知道如何改變東西,所以動畫只出現在ContentPresenter
的範圍內?
Hi @Grace Feng,請在原帖中查看我的UPDATE。如果我使用ContentPresenter,那麼每次使用文本更改時都可以使用它。唯一的問題是,如果我使用'VerticalOffset = -100',那麼文本就會從ContentPresenter的邊界外漂浮,這看起來很奇怪。 – Cleve
@Cleve,我的錯誤,我只注意到你將'HorizontalOffset'改爲'VerticalOffset',你實際上也改變了你的動畫目標。我稍後會更新我的答案。 –
@Cleve,我已經更新了我的答案,對不起我的錯誤。 –