【发布时间】:2010-11-19 11:28:23
【问题描述】:
我有一个奇怪的问题正在给我们带来麻烦。
我们有一个简单的 C# Wpf UserControl。它是一个进度条——没什么花哨的——只是一个根据对 Value 和 MaxValue 的绑定来改变大小的边框。它在 99% 的情况下都能正常工作,我们在代码中的十几个地方都使用它——包括启动画面。
它在初始屏幕中总是可以正常工作 - 所以它总是在我们的应用程序中加载和工作。
问题在于,有时(我们无法预测或理解何时)进度条构造函数中的 InitializeComponent() 调用会引发 System.Exception。查看编译期间创建的progressbar.g.cs 文件(obj/Debug 文件夹),我可以看到由于找不到progressbar.xaml 文件而引发了异常。当然,我没有更改 g.cs 文件中的任何代码,也没有在这个 UserControl 中做任何花哨的事情。
System.Exception: The component 'MyProject.ControlLibrary.ProgressBar' does not have a resource identified by the URI '/MyProject.ControlLibrary;component/progressbar.xaml'.
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at MyProject.ControlLibrary.ProgressBar.InitializeComponent() in d:\Projectfolder\MyProject.ControlLibrary\ProgressBar.xaml:line 1
at MyProject.ControlLibrary.ProgressBar..ctor() in D:\projectfolder\MyProject.ControlLibrary\ProgressBar.xaml.cs:line 26
at ProjectName.UI.VideoViewer..ctor() in D:\projectfolder\UI\VideoViewer.xaml.cs:line 26
Source: PresentationFramework
我不明白为什么 progressbar.xaml 资源有时会丢失,尤其是考虑到它在应用程序运行时至少一次总是可以正常工作。
UserControl 包含在名为 MyProject.ControlLibrary.dll 的项目中。该项目似乎配置正确,因为它包含其他没有显示任何问题的用户控件 - 除了另一个具有相同问题的类似 UserControl。
我对此没有任何想法 - 所以任何建议都会有所帮助。我正在使用 VisualStudio 2008 和 .net 3.5
【问题讨论】:
标签: c# wpf xaml user-controls