Wpf ResourceDictionary使用UserControl->;无法解析UserControl中的资源
我在App.xaml中将资源定义为ResourceDictionary:Wpf ResourceDictionary使用UserControl->;无法解析UserControl中的资源,wpf,xaml,user-controls,resources,resourcedictionary,Wpf,Xaml,User Controls,Resources,Resourcedictionary,我在App.xaml中将资源定义为ResourceDictionary: <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/AssemblyName;co
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/AssemblyName;component/Resources/HamburgerMenuStyles.xaml" />
<!--…-->
</ResourceDictionary.MergedDictionaries>
<converters:LanguageConverter x:Key="LanguageConverter"/>
<!--…-->
</ResourceDictionary>
</Application.Resources>
然后,在上述代码中包含的ResourceDictionary“HamburgerMinusTyles.xaml”中,我使用了UserControl:
<mah:HamburgerMenu.OptionsItemsSource>
<mah:HamburgerMenuItemCollection>
<mah:HamburgerMenuIconItem Label="{localization:Loc tabConf}">
<mah:HamburgerMenuIconItem.Icon>
<!--…-->
</mah:HamburgerMenuIconItem.Icon>
<mah:HamburgerMenuIconItem.Tag>
<controls:Settings/> <!--Calling the UserControl here-->
</mah:HamburgerMenuIconItem.Tag>
</mah:HamburgerMenuIconItem>
</mah:HamburgerMenuItemCollection>
</mah:HamburgerMenu.OptionsItemsSource>
我得到的错误是,用户控件中使用的资源(在那里使用的资源也放在App.xaml中)无法解析,即使代码编译并工作。怎么会?我在UserControl.xaml本身中没有收到intellisense错误
例如:
Visual Studio抱怨UserControl中使用了转换器,该转换器在App.xaml中定义为资源,并且在控件xaml+编译和工作时未显示任何错误。将“缺少的”资源添加到控件中,编译并再次删除资源解决了我的问题:
<mah:HamburgerMenu.OptionsItemsSource>
<mah:HamburgerMenuItemCollection>
<mah:HamburgerMenuIconItem Label="{localization:Loc tabConf}">
<mah:HamburgerMenuIconItem.Icon>
<!--…-->
</mah:HamburgerMenuIconItem.Icon>
<mah:HamburgerMenuIconItem.Tag>
<controls:Settings>
<controls:Settings.Resources>
<converters1:InvertBoolConverter x:Key="InvertedBoolConverter"/>
</controls:Settings.Resources>
</controls:Settings>
</mah:HamburgerMenuIconItem.Tag>
</mah:HamburgerMenuIconItem>
</mah:HamburgerMenuItemCollection>
</mah:HamburgerMenu.OptionsItemsSource>
这似乎是个错误。没有问题:-)上面提供的XAML在哪个资源字典中?在哪个资源字典中是产生错误的资源?这两个资源字典都包含在App.xaml资源中吗,在哪里?我不清楚您描述的内容在哪里。然而。如果由于资源不可用而导致出现设计器错误,那么就设计器而言,这可能不会合并。您可以添加仅限设计师使用的资源。仅限设计时使用的资源:您好,我更新了我的问题,并尝试了Andys的建议,使用标记true for HamburgerMenuStyles.xaml修改csproj。不幸的是,这不起作用……我现在已经解决了我的问题,请参见下面的答案。谢谢你的帮助!