The resource could not be resolved (VS 2010 RC)
Asked Answered
S

2

6

I've got WPF 4 app that has a number of UserControls that share styles in their child controls. So I'm creating a number of styles in my App.xaml as . For example:

<Style x:Key="ViewTitle" TargetType="{x:Type Border}">
    <Setter Property="BorderBrush" Value="LightGray" />
    <Setter Property="HorizontalAlignment" Value="Stretch" />
    <Setter Property="VerticalAlignment" Value="Top" />
</Style>

Then in my UserControls I use StaticResource to reference them, for example:

<Border Style="{StaticResource ViewTitle}">
    <TextBlock Margin="6,3,4,5" FontSize="18" FontWeight="Bold" Foreground="White" HorizontalAlignment="Left" Text="Host Management" />
</Border>

This all works fine. The problem is the Visual Studio 2010 RC is putting a blue squiggly under the StaticResource reference and saying: The resource "ViewTitle" could not be resolved.

What's up with that? Is this a problem with Visual Studio or am I doing something wrong?

Scad answered 6/3, 2010 at 0:52 Comment(2)
Do you get an error at compile or run time, or just the blue squiggly? If it's just the blue squiggly, and everything works fine at run time, I'd write it off as designer fail.Christlike
Yeah just a designer squiggly. It builds and runs fine. I'm new to WPF so I was suspicious I was doing it wrong.Scad
C
10

From your note in the comments that "it builds and runs fine," this is almost certainly a problem with Visual Studio. Unfortunately, the VS WPF designer is infamously buggy, and will often fail to resolve or handle perfectly legal XAML. The only true test, therefore, is to compile and run: annoying, but just something one learns to live with.

You may find that the Expression Blend designer handles this situation better. Blend aims more at being a visual designer (graphic designers are the main target users) but Blend 3 has significantly improved support for editing XAML source code. It may be worth giving that a try.

Christlike answered 6/3, 2010 at 1:5 Comment(0)
C
1

This problem has been "solved" in Expression Blend 4.

Blend 4 automatically gives you the option of locating design time resources if you have a resource that could nor be resolved.

Blend will then make a DesignTimeResourceDictionary from which it will access your resources.

However, this will not help you much if VS2010 is your main editor :(

The solution with Blend 4:

http://adamkinney.wordpress.com/2010/05/04/design-time-resources-in-expression-blend-4-rc/

Catachresis answered 12/10, 2010 at 11:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.