L'animation d'une zone de texte.De premier plan dans WPF

Est-il de toute façon pour animer un TextBox.ForegroundProperty?

<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>

Mon essayé les story-boards sont:

<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>

Aucune de ces travaux. Une idée? Est-il même possible?

  • Vous essayez d'animer la SolidColorBrush de PART_ContentHost, toutefois, il ne contient pas de pinceau. Avez-vous essayez d'attribuer une première brosse à dents? (Et où est-ce que votre contenu aller?)
  • Oui. Voir la mise à jour de question s'il vous plaît.
  • Eh bien, je vois encore <ScrollViewer x:Name="PART_ContentHost" ... Background="{x:Null}"/>. Si vous essayez d'animer une propriété sur null objet, à droite?
  • Non, je ne suis pas d'animer Background à tous. La propriété Target est Foreground
  • Oh, je vois. Vous essayez d'animer une propriété attachée Textblock.Foreground sur le PART_ContentHost. Mais c'est toujours le même: PART_ContentHost n'est pas tout, il est donc null. Pourriez-vous essayer d'assigner une valeur à elle?
  • Non, je ne suis pas d'animer Textblock.Foreground, mais j'ai essayé tous les story-boards mentionné dans la question; et oui, sur chaque scénario d'utilisation, j'ai corriger les valeurs de toutes les propriétés (y compris votre mentionnés).
  • Ok, je ne savais pas que ScrollViewer a ses propres biens Foreground. Mais néanmoins, cette propriété est null, car il n'est pas attribué pour PART_ContentHost. Ainsi que de la propriété attachée TextElement.Foreground. Et pour le sans nom Grid, trop.

InformationsquelleAutor javad amiry | 2013-08-24