Visual Studio 2012 XAML设计器在App.xaml位于不同程序集时无法显示正确内容

5

我正在将一个WPF应用程序从VS 2010迁移到VS 2012。

我有一个包含App.xaml和所有WPF控件的单独类库的主要可执行文件。 在VS2012(SP3)中,XAML设计师不显示在App.xaml中定义的MergedResourceDictionary中的任何样式,但在VS 2010中可以正常显示...

为了测试的目的,我将App.xaml移动到了我的类库中。然后,VS 2012设计器正确地显示了所有内容。

由于类库不能包含App.xaml,因此这不是一个解决方案。

有什么想法吗?

我的App.xaml如下所示:

<Application x:Class="MyApplication.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Startup="AppStartup">
<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/OtherAssemblyName;component/Resources/Resource1.xaml" />
            <ResourceDictionary Source="pack://application:,,,/OtherAssemblyName;component/Resources/Resource2.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

1个回答

0

虽然这是一个旧问题,但我会为任何未来可能遇到类似情况的人回答它。

最安全的方法是创建一个新的ResourceDictionary文件,并在其中添加MergedResourceDictionaries。

然后在您的用户控件/页面/窗口中引用该ResourceDictionary - 所有它们都需要引用。

<UserControl.Resources>
    <ResourceDictionary Source="GlobalResources.xaml" />
<UserControl.Resources>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接