Visual Studio 2010使用Application.xaml; Blend 4 使用 App.xaml
以前,我正在编写的项目中的所有应用程序级资源都存储在 App.xaml
中。然后我决定从 VS 2008 迁移到 2010,这就是麻烦开始的地方。
迁移后,我尝试使用测试窗口而不是正常的启动窗口进行一些测试。更改启动对象后,突然我遇到了很多编译错误,而不是(长话短说)导致发现现在有两个文件保存与项目关联的应用程序级资源:App.xaml< /code> (原始)和
Application.xaml
(此时确实是空的)。我将所有资源(以及合并的字典)迁移到 Application.xaml
,就 Visual Studio 而言,一切都再次正常。
然后我发现 Blend 仍然想使用 App.xaml
。我创建了几个资源并将它们放置在 Application.xaml
中,发现当我用 Blend 编译时它们没有被使用(但当我用 VS 编译时它们被使用)。
在哪里指定哪个 XAML 是顶级 WPF 资源文件?这已经失控了……
Previously all application level resources in a project I am authoring were stored in App.xaml
. Then I decided to migrate from VS 2008 to 2010 and that is where the trouble started.
After migrating, I tried to do a little testing using a testing window instead of the normal startup window. After changing the startup object, suddenly I was faced with lots of compile errors and what not which (long story short) resulted in finding that there was now two files which held application level resources associated with the project: App.xaml
(the original), and Application.xaml
(at this time veritably empty). I migrated all of the resources (as well as merged dictionaries) over to the Application.xaml
, and all was again right with the world so far as Visual Studio was concerned.
I then found out that Blend still wanted to use the App.xaml
. I had created several resources and placed them in the Application.xaml
, and saw that they were not being used when I compiled with Blend (but they were being used when I compiled with VS).
Where does one specify which XAML is the top level WPF resource file? This is getting out of hand...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您选择的编程语言,命名略有不同。
Visual Basic WPF 项目使用 Application.xaml,而 C# 项目将其命名为 App.xaml。
您可能知道所有 .NET 应用程序都需要 Main 方法。此外,Windows 应用程序需要消息泵才能连接到 Windows 消息系统。在 WPF 中,您可以使用 Application 类开始侦听 Windows 消息。
以下是您可以明确执行此操作的方法。
VB
C#
由于创建此类代码对于 WPF 应用程序很常见,因此您可以通过定义从 System.Windows.Application 派生的 XAML 文件和类并将其生成操作指定为 ' 来告诉 MSBuild 编写此代码应用程序定义'。
在您的情况下,您可以在解决方案资源管理器中选择正确的文件,而不是编辑 VbProj 文件,然后更改构建操作。
There are slight differences in naming depending on what programming language you choose.
Visual Basic WPF projects use Application.xaml, while C# projects name it App.xaml.
As you probably know all .NET apps need a Main method. Also, windows apps need a message pump to get hooked to the Windows messaging system. IN WPF you can use the Application class to start listening to the windows messages.
Here's how you can do it explicitly.
VB
C#
Since creating this type of code is common for WPF applications you can tell MSBuild to write this code by defining a XAML file and class that derives from System.Windows.Application and specifing its build action as 'ApplicationDefinition'.
In your situation, instead of editing the VbProj file, you could just select the correct file in Solution Explorer and change the BuildAction.