我在Visual Studio 2017中使用.Net 4.6.1
我在构建应用程序时使用了WPF样式,控件,转换器等的库(在项目A中)。我们的想法是,如果有企业品牌变更,我们可以重新发布库,并且所有引用它的应用程序都将被重新标记。
项目A没有错误或警告,并且正确构建以生成.dll文件。
然而,当我在项目B中引用.DLL时,引用某些.DLL组件的xaml会永久地给出Loading designer... You can continue working while the designer is loading in the background
消息。当我尝试启动Project B时,它告诉我它处于中断模式,使用System.StackOverflowException
就是这样。
我尝试在app.xaml文件中添加和删除行:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/WPFLibrary;component/Styles/Colours.xaml"/>
<ResourceDictionary Source="pack://application:,,,/WPFLibrary;component/Styles/Brushes.xaml"/>
<ResourceDictionary Source="pack://application:,,,/WPFLibrary;component/Styles/Text.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
并且这样做给了我一个提示,也许是因为只有一些参考文献(或者可能有太多的参考文献?)导致设计师失败,但我有一段时间试图找到正在发生的事情。
您是否知道如何调试此问题,因为问题似乎是项目A正确构建?例如,在设计时可能发现问题的任何提示或技巧或额外工具?
或者,任何关于如何检查项目B中的所有内容的建议都应该是受欢迎的。我检查了所有引用,命名空间和资源字典,并确信语法是正确的,但也许有一些我可能错过的问题?
所以,事实证明,这是你周末离开的烦人问题之一,当你回来时,它已经改变了它的外观。我回来了,再也无法得到堆栈溢出错误。
报告的错误是项目A中的UserControl未能找到同一项目中内置的资源之一。我能够通过将Merged字典中的引用从标准更改为Pack URI格式来解决此问题(本地路径引用仅在项目本身中查看时才起作用 - 它们在DLL中失败)。由此:
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Styles/Buttons.xaml"/>
<ResourceDictionary Source="/Styles/Gradients.xaml"/>
<ResourceDictionary Source="/Styles/Text.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
对此:
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/WPFLibrary;component/Styles/Buttons.xaml"/>
<ResourceDictionary Source="pack://application:,,,/WPFLibrary;component/Styles/Gradients.xaml"/>
<ResourceDictionary Source="pack://application:,,,/WPFLibrary;component/Styles/Text.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
从中我了解到 - 本地引用仅在资源字典之间的DLL中本地工作;如果您希望使用DLL中的UserControl,则必须使用包格式。将来我会在任何地方使用Pack URI,它们不会导致语法错误!