【发布时间】:2019-11-24 22:38:18
【问题描述】:
我正在尝试让ContentControl 应用ContentThemeTransition,其中内容将是一个字符串,因此当字符串通过绑定更改时,新字符串将动画化。我不能使用ContentThemeTransition带有TextBlock,因为这不是从ContentControl 派生的。
下面是一些显示问题的示例 XAML。如果我编辑 Textbox 中的文本(它表示我的 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 如上所述,新值在ContentControli.e 之外向下动画。它在控件范围之外可见。任何人都知道如何更改内容以使动画仅出现在ContentPresenter 的范围内?
【问题讨论】:
标签: c# uwp transition uwp-xaml