Есть ли все равно, чтобы анимировать TextBox.ForegroundProperty
?Анимация TextBox.Foreground в WPF
<Color x:Key="NormalColor">#FF666666</Color>
<SolidColorBrush x:Key="NormalBrush" Color="{StaticResource NormalColor}" />
<Color x:Key="MouseOverColor">#FF666666</Color>
<SolidColorBrush x:Key="MouseOverBrush" Color="{StaticResource MouseOverColor}" />
<ControlTemplate x:Key="RegularTextBoxTemplate" TargetType="{x:Type TextBox}">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0:0:0.1"/>
</VisualStateGroup.Transitions>
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<!-- storyboard to animating foreground here... -->
</Storyboard>
</VisualState>
</VisualStateGroup >
</VisualStateManager>
<ScrollViewer x:Name="PART_ContentHost"
BorderThickness="0"
IsTabStop="False"
Background="{x:Null}"/>
</Grid>
</ControlTemplate>
<Style x:Key="RegularTextBox" TargetType="{x:Type TextBox}">
<Setter Property="Foreground" Value="{StaticResource NormalBrush}"/>
<Setter Property="Template" Value="{StaticResource RegularTextBoxTemplate}"/>
</Style>
Мои пытались раскадровки:
<ColorAnimationUsingKeyFrames Storyboard.TargetName="PART_ContentHost"
Storyboard.TargetProperty="(Foreground).(SolidColorBrush.Color)">
<EasingColorKeyFrame KeyTime="0" Value="{StaticResource MouseOverColor}" />
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="PART_ContentHost"
Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)">
<EasingColorKeyFrame KeyTime="0" Value="{StaticResource MouseOverColor}" />
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="PART_ContentHost"
Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)">
<EasingColorKeyFrame KeyTime="0" Value="{StaticResource MouseOverColor}" />
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames
Storyboard.TargetProperty="(Foreground).(SolidColorBrush.Color)">
<EasingColorKeyFrame KeyTime="0" Value="{StaticResource MouseOverColor}" />
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames
Storyboard.TargetProperty="(TextBox.Foreground).(SolidColorBrush.Color)">
<EasingColorKeyFrame KeyTime="0" Value="{StaticResource MouseOverColor}" />
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames
Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)">
<EasingColorKeyFrame KeyTime="0" Value="{StaticResource MouseOverColor}" />
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames
Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)">
<EasingColorKeyFrame KeyTime="0" Value="{StaticResource MouseOverColor}" />
</ColorAnimationUsingKeyFrames>
Ни один из них не работает. Есть идеи? Возможно ли это?
Вы пытаетесь анимировать 'SolidColorBrush'' PART_ContentHost', однако он не содержит кисти. Вы пытались присвоить некоторую начальную кисть? (И куда идет ваш контент?) – Vlad
@ Vlad Да. См. Обновленный вопрос. –
Ну, я все еще вижу ' '. Итак, вы пытаетесь анимировать свойство на объекте «null», верно? –
Vlad