Aliasing Resources (WPF)

Posted by Noldorin on Stack Overflow See other posts from Stack Overflow or by Noldorin
Published on 2009-07-17T14:29:37Z Indexed on 2010/06/05 13:02 UTC
Read the original article Hit count: 422

Filed under:
|
|
|
|

I am trying to alias a resource in XAML, as follows:

<UserControl.Resources>

    <StaticResourceExtension x:Key="newName" ResourceKey="oldName"/>

</UserControl.Resources>

oldName simply refers to a resource of type Image, defined in App.xaml.

As far as I understand, this is the correct way to do this, and should work fine. However, the XAML code gives me the superbly unhelpful error:

"The application XAML file failed to load. Fix errors in the application XAML before opening other XAML files."

This appears when I hover over the StaticResourceExtension line in the code (which has a squiggly underline). Several other errors are generated in the actual Error List, but seem to be fairly irrelevant and nonsenical (such messages as "The name 'InitializeComponent' does not exist in the current context"), as they all disappear when the line is removed.

I'm completely stumped here. Why is WPF complaining about this code? Any ideas as to a resolution please?

Note: I'm using WPF in .NET 3.5 SP1.

Update 1:
I should clairfy that I do receive compiler errors (the aforementioned messages in the Error List), so it's not just a designer problem.

Update 2:
Here's the relevant code in full...

In App.xaml (under Application.Resource):

<Image x:Key="bulletArrowUp" Source="Images/Icons/bullet_arrow_up.png" Stretch="None"/>
<Image x:Key="bulletArrowDown" Source="Images/Icons/bullet_arrow_down.png" Stretch="None"/>

And in MyUserControl.xaml (under UserControl.Resources):

<StaticResourceExtension x:Key="columnHeaderSortUpImage" ResourceKey="bulletArrowUp"/>
<StaticResourceExtension x:Key="columnHeaderSortDownImage" ResourceKey="bulletArrowDown"/>

These are the lines that generate the errors, of course.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about xaml