0

In a given xaml, there is a part:

<ColorAnimation Storyboard.TargetProperty="Background.(SolidColorBrush.Color)" To="Black" Duration="0:0:3"/> 

If I specify only "Background", then it doesn't work. Why? Where can I get some info about making path?

P.S.: I seen some really crazy path, like "(blablabla).(blablabla).(blablabla.blablabla)" and it makes me nervous, because I can't find what does it means easily...

3
  • 1
    Background is of a Brush type and this is ColorAnimation which can animate Color that is published by SolidColorBrush. For rules check PropertyPath XAML Syntax Commented Mar 25, 2014 at 10:37
  • @dkozl, it is still not very clear how to form the path. To example, "Background.Color" is working in my case. But this SolidColorBrush part inside brackets looks like type conversion and given description (in link) is very poor, limited and I feel it is incomplete. Do you know any better one? Commented Mar 25, 2014 at 10:54
  • 1
    Yes, Background.Color in case of SolidColorBrush will work just as well. Both cases will fail if there is no Color property just Background.(SolidColorBrush.Color) expects it to be SolidColorBrush where Background.Color will be happy with any Color property so if you would have another Brush type with Color property it will work as well Commented Mar 25, 2014 at 11:05

2 Answers 2

2

It doesn't work if you only specify Background because the storyboard animates a color, and this color is the Color property of the Background property.

Background is a brush, so it could contain any type of brush. In order to access the Color the brush needs to be converted to a SolidColorBrush.

This is basically what the expression Background.(SolidColorBrush.Color) does. It converts Background to a SolidColorBrush and then accesses the Color property from it.

In c# code you would write

 ((SolidColorBrush)Background).Color = someColor; 
Sign up to request clarification or add additional context in comments.

2 Comments

I didn't noticed it was a Brush. Thanks. The only question left is syntax. I would expect something like "((SolidColorBrush)Background).Color", but in xaml it appears as Background.(SolidColorBrush.Color). Do you know any reference to this? Type conversion xaml gives TypeConverters as result in google.
Found myself. It is called type-qualified property.
1

Try this

Example1

 <Button> <Button.Triggers> <EventTrigger RoutedEvent="Loaded"> <BeginStoryboard> <Storyboard> <ColorAnimation Storyboard.TargetProperty="Background.Color" From="Transparent" To="Red" Duration="0:0:0.1"></ColorAnimation> </Storyboard> </BeginStoryboard> </EventTrigger> </Button.Triggers> </Button> 

example2

 <Grid> <Button x:Name="Button"></Button> <Grid.Triggers> <EventTrigger RoutedEvent="Loaded"> <BeginStoryboard> <Storyboard> <ColorAnimation Storyboard.TargetName="Button" Storyboard.TargetProperty="Background.Color" From="Transparent" To="Green" Duration="0:0:0.1"></ColorAnimation> </Storyboard> </BeginStoryboard> </EventTrigger> </Grid.Triggers> </Grid> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.