资源不能被解析(VS 2010 RC)资源、VS、RC

2023-09-02 10:51:38 作者:心里葬着一个未亡人

我有4 WPF应用程序,有一些用户控件的份额风格在他们的子控件。所以我创造了我的App.xaml多项风格。例如:

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>

然后在我的用户控件我使用的StaticResource引用它们,例如:

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>

这一切工作正常。问题是Visual Studio 2010 RC是把一个蓝色的波浪下的StaticResource参考,并说:资源ViewTitle无法解析

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.

怎么了呢?这是与Visual Studio还是我做错了什么问题?

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

推荐答案

从你的备注栏中说,它建立并运行良好,这几乎可以肯定是与Visual Studio的一个问题。不幸的是,VS WPF设计是臭名昭著的越野车,并经常无法解决或处理完全合法的XAML。唯一真正的考验,因此要编译并运行:讨厌,但只是一些人们学会忍受

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.

您的可以的发现,前pression Blend中的设计处理这种情况更好。混合的目的更多是一个可视化设计(平面设计师的主要目标用户),但3混合编辑XAML源$ C ​​$ C有显著改善的支持。这可能是值得给予一个尝试。

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.