Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3443412
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:47:16+00:00 2026-05-18T08:47:16+00:00

Dear all, I’ve got the following problem with WPF 3.5. When accessing a dynamic

  • 0

Dear all, I’ve got the following problem with WPF 3.5. When accessing a dynamic resource in a storyboard, the value is wrong (seemingly the reference is not resolved) when the resource is defined in the window which contains the target control.

What am I doing wrong, and is there a right way (or at least a workaround)? Basically I want the storyboard to use the colors from dynamic resource, and I can only put those resources locally at the window level.

Example code:

<Window
    x:Class="Test.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300"
    MouseDoubleClick="Window_MouseDoubleClick">
    <Window.Resources>
        <Color x:Key="MyColor">Blue</Color>
    </Window.Resources>
    <Grid x:Name="outer">
        <Grid.Resources>
            <Storyboard x:Key="MyBoard">
                <ColorAnimationUsingKeyFrames
                    Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
                    <LinearColorKeyFrame KeyTime="0:0:0" Value="Red"/>
                    <LinearColorKeyFrame KeyTime="0:0:1" Value="{DynamicResource MyColor}"/>
                </ColorAnimationUsingKeyFrames>
            </Storyboard>
            <SolidColorBrush x:Key="MyBrush" Color="{DynamicResource MyColor}"/>
        </Grid.Resources>
        <Grid x:Name="inner" Background="Green"/>
    </Grid>
</Window>

Code-behind:

public partial class Window1 : Window
{
    public Window1()
    {
        InitializeComponent();
    }

    private void Window_MouseDoubleClick(object sender, MouseButtonEventArgs e)
    {
        Storyboard s = (Storyboard)outer.FindResource("MyBoard");
        inner.BeginStoryboard(s);
        //SolidColorBrush b = (SolidColorBrush)outer.FindResource("MyBrush");
        //inner.Background = b;
    }
}

The problem is that the reference Value="{DynamicResource MyColor}" is not working, the value is transparent.

I tried the following:

  1. If I move the definition of MyColor from the window resources to application resources, the code works as expected.
  2. If I replace the storyboard start with assigning of another resource (comment out first two lines in Window_MouseDoubleClick, and uncomment the rest), the dynamic resource access works.
  3. The behaviour in .NET 4/WPF 4 is the same.
  4. I tried creating the storyboard from the code behind (just for test), but cannot convert the line <LinearColorKeyFrame KeyTime="0:0:1" Value="{DynamicResource MyColor}"/> into procedural code, because LinearColorKeyFrame is not FrameworkElement. Maybe this is root of the problem?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:47:17+00:00Added an answer on May 18, 2026 at 8:47 am

    I don’t know if there’s a way to do it with XAML and binding, I couldn’t get a similar thing working in Silverlight, but as a workaround you can create the StoryBoard and animations in code:
    http://msdn.microsoft.com/en-us/library/cc189069(VS.95).aspx#procedural_code

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Dear all, I have a select query that currently produces the following results: DoctorName
Dear g++ hackers, I have the following question. When some data of an object
Dear all, I am writing a python program that is retrieving edifact log messages
Dear all, I save formatted text (bold, changed in font, style...etc) in an nvarchar(max)
Dear all, I have a question about Facebook Page: ( NOT user profile page,
Dear all: In advance, thank you for your time. Lately, I have decided to
Dear all, I now have a preliminary macro (defmacro key-if(test &key then else) `(cond
Dear all,I am now using a webtool http://fiddesktop.cs.northwestern.edu/mmp/scrape?url= to parse a webpage. For example,we
Dear all,Now i have this question in my java program,I think it should be
Dear All, please help me since I'm newbie in SQL Server. I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.