2013-05-09 6 views
1

J'essaie de faire clignoter le premier plan d'une étiquette. J'ai essayé le code suivant mais j'ai l'exception suivante et je ne sais pas comment le résoudre.WPF clignotant étiquette de premier plan

'System.Windows.Media.Animation.ColorAnimation' animation object cannot be used 
to animate property 'Foreground' because it is of incompatible type 
'System.Windows.Media.Brush'. 

En utilisant cette XAML:

<Label Content="{Binding Path=SendingAlert, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" 
         Foreground="Transparent" 
         HorizontalAlignment="Right"> 
        <Label.Style> 
         <Style> 
          <Style.Triggers> 
           <DataTrigger Binding="{Binding Path=IsSending, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" 
              Value="True"> 
            <DataTrigger.EnterActions> 
             <BeginStoryboard> 
              <Storyboard 
                Storyboard.TargetProperty="Foreground" 
                Duration="0:0:0.5"> 
               <ColorAnimation From="Transparent" To="Red" AutoReverse="True" RepeatBehavior="Forever"/> 
              </Storyboard> 
             </BeginStoryboard> 
            </DataTrigger.EnterActions> 
           </DataTrigger> 
           <!--<DataTrigger Binding="{Binding IsSending}" Value="False"> 
            <Setter Property="Foreground" Value="Transparent"/> 
           </DataTrigger>--> 
          </Style.Triggers> 
         </Style> 
        </Label.Style> 
       </Label> 

et où

public bool IsSending 
    { 
     get { return !CanDoActions; } 
    } 

    private string _sendingAlert = "sending";//string.Empty; 
    public string SendingAlert 
    { 
     get { return _sendingAlert; } 
     set 
     { 
      _sendingAlert = value; 
      OnPropertyChanged(() => SendingAlert); 
     } 
    } 

Toute idée de comment résoudre ce problème?

+9

http://stackoverflow.com/questions/2652831/blinking-textblock –

+1

http://stackoverflow.com/questions/15822519/making- une- wpf-label-ou-autre-élément-flash-using-animation –

Répondre

1

La propriété Foreground est de type Brush, ce qui est différent d'un objet de type Color

Vous pouvez utiliser un ColorAnimiation pour animer un objet de type Color, mais pas de type Brush, ainsi Animez votre brosse avant-plan , vous devez définir la propriété du Brush.Color, comme ceci:

Storyboard.TargetProperty="(Foreground).(SolidColorBrush.Color)" 
Questions connexes