WPF ResourceDictionary无法找到源

时间:2018-10-24 05:20:42

标签: wpf user-controls resourcedictionary

我的XAML设计人员不断尖叫“找不到资源xxx.xaml”。我已经尝试过打包应用程序和绝对路径URI格式

  • "pack://application:,,,/ReferencedAssembly;component/Subfolder/ResourceFile.xaml"
  • "pack://application:,,,/Subfolder/ContentFile.xaml"
  • "/AssemblyName;component/FilePath.xaml"

项目文件结构(无法发布图片,没有足够的代表):

root/App.xaml
root/MainWindow.xaml
root/Res
root/Res/PalleteBlue.xaml
root/UserControl
root/UserControl/NavigationDrawer.xaml
root/UserControl/Res
root/UserControl/Res/NavigationDrawerResource.xaml

NavigationDrawer.xaml使用NavigationDrawerResource.xaml
MainWindow.xaml的实例为NavigationDrawer.xaml
NavigationDrawer上的XAML设计器没有问题,但是在MainWindow上,它不断告诉Cannot locate resource usercontrol/res/navigationdrawerresource.xaml

这是NavigationDrawer.xaml

中的资源声明
<UserControl.Resources>
  <ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
      <ResourceDictionary Source="pack://application:,,,/UserControl/Res/NavigationDrawerResource.xaml"/>
      <ResourceDictionary Source="pack://application:,,,/Res/PalleteBlue.xaml"/>
    </ResourceDictionary.MergedDictionaries>
  </ResourceDictionary>
</UserControl.Resources>

这是MainWindow.xaml如何添加NavigationDrawer的实例

xmlns:uc="clr-namespace:InfiniteLite.View.UserControl"

<Grid>
  <uc:NavigationDrawer></uc:NavigationDrawer>        
</Grid>

这会在Cannot locate resource....标签上产生<uc:NavigationDrawer>错误,但项目可以很好地调试

0 个答案:

没有答案