WPF - App.xaml 的 Build Action = Page 时在设计时访问资源 [英] WPF - access to resources in design time when App.xaml's Build Action = Page
问题描述
我将 App.xaml 的构建操作更改为Page",这样我就可以处理启动画面并确保我的应用程序仅作为单个实例运行(有我自己的入口点).它在运行时工作正常,但在设计时应用程序无法再看到我的资源.资源位于位于同一项目中的单独 xaml 文件中.如何让我的应用在设计时再次看到资源?
谢谢
如果我理解正确,您是在 app.xaml 中加载应用程序范围的资源吗?在这种情况下,您可以这样做:
<预><代码>App app = new App();//获取程序集名称是你自己的方法string assemblyName = GetAssemblyName(Assembly.GetExecutingAssembly());Uri resourceLocater = new Uri("/" + assemblyName + ";component/app.xaml", UriKind.Relative);System.Windows.Application.LoadComponent(app, resourceLocator);MainWindow mainWindow = new MainWindow();应用程序运行(主窗口);然后你的资源将被加载
/丹尼尔
I changed the build action of my App.xaml to "Page" so I could handle a splash screen and make sure my application run as a single instance only (having my own entry point). It works fine in run-time but in design-time the application cannot see the my resources anymore. Resources are in separate xaml files located in the same project. How can I make my app see the resources in design-time again?
Thanks
If I understand you correct, you're loading Application-wide resources in the app.xaml? In this case you can do like this:
App app = new App();
//Get assembly name is your own method
string assemblyName = GetAssemblyName(Assembly.GetExecutingAssembly());
Uri resourceLocater = new Uri("/" + assemblyName + ";component/app.xaml", UriKind.Relative);
System.Windows.Application.LoadComponent(app, resourceLocater);
MainWindow mainWindow = new MainWindow();
app.Run(mainWindow);
Then your resources will be loaded
/Daniel
这篇关于WPF - App.xaml 的 Build Action = Page 时在设计时访问资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!