Gforse
Gforse

Reputation: 363

Storyboard To value staticresource

Can figure this one out, I have some staticresources in aaplication.xaml

These staticresources i use in differtent places, per design. Now i want to use a Staticresource to a Coloranimation in a Storyboard but i can't get it to work i get the error: An object of the type "System.Windows.Media.SolidColorBrush" cannot be applied to a property that expects the type "System.Nullable1[[System.Windows.Media.Color,....]]

Code so far:

Application.XAML

<Application.Resources>
     <SolidColorBrush x:Key="GreenLight" Color="#0CAF12" />
</Application.Resources>

In a usercontrol label style:

<Setter Property="Label.Content" Value="Connected" />
<DataTrigger.EnterActions>
    <BeginStoryboard Name="StoryConnected">
          <Storyboard Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)">
                 <ColorAnimation Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)" To="{StaticResource GreenLight}" Duration="0:0:0.5" />
           </Storyboard>
     </BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
      <RemoveStoryboard BeginStoryboardName="StoryConnected" />
</DataTrigger.ExitActions>

Upvotes: 0

Views: 393

Answers (1)

mm8
mm8

Reputation: 169150

This won't work because the Storyboard cannot be frozen when you bind the To property:

To="{Binding Color, Source={StaticResource GreenLight}}"

So you actually need to set the To property to a Color object, i.e. define your resource like this:

<Color x:Key="GreenLight">#0CAF12</Color>

Upvotes: 4

Related Questions