资源无法解析(VS 2010 RC)

发布于 2024-08-24 10:53:54 字数 804 浏览 7 评论 0原文

我有一个 WPF 4 应用程序,它有许多用户控件,它们在其子控件中共享样式。因此,我在 App.xaml 中创建了多种样式,如下所示。例如:

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

然后在我的 UserControls 中,我使用 StaticResource 来引用它们,例如:

<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”。

这是怎么回事?这是 Visual Studio 的问题还是我做错了什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你又不是我 2024-08-31 10:53:54

从您在评论中的注释“它构建并运行良好”来看,这几乎肯定是 Visual Studio 的问题。不幸的是,VS WPF 设计器存在着臭名昭著的错误,并且经常无法解析或处理完全合法的 XAML。因此,唯一真正的测试是编译和运行:虽然很烦人,但只是人们学会忍受的东西。

可能发现Expression Blend设计器可以更好地处理这种情况。 Blend 的目标更多地是成为一个视觉设计师(图形设计师是主要目标用户),但 Blend 3 显着改进了对编辑 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.

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.

甩你一脸翔 2024-08-31 10:53:54

此问题已在 Expression Blend 4 中“解决”。

如果您有无法解决的资源,Blend 4 会自动为您提供定位设计时资源的选项。

然后 Blend 将创建一个 DesignTimeResourceDictionary,从中访问您的资源。

但是,如果 VS2010 是您的主要编辑器,这对您没有多大帮助:(

Blend 4 的解决方案:

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

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文