Reputation:
I would like to have my own application class that inherits from System.Windows.Application. The problem is that in the Application.xaml file, I have to declare the app like this :
<src:MyBaseApplication x:Class="MyApplication"
xmlns:src="clr-namespace:MyApplication;assembly=WpfTestApplication"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="FPrincipal.xaml">
<Application.Resources>
</Application.Resources>
</src:MyBaseApplication>
It works great at runtime, but when I edit the project properties, I receive the following error message by the project properties editor of Visual Studio :
An error occurred trying to load the application definition file for this project. The file '[...]\Application.xaml' could not be parsed. Please edit the file in the XAML editor to fix the error. Could not find the expected root element "Application" in the application definition file.
The project is a VB.NET project. Somebody have a workaround? I want to keep the application.xaml file.
Upvotes: 7
Views: 2668
Reputation: 1897
I've tried it with Visual Studio 2013 but I did not experience any problem. So, it should be VS 2008 specific. Did you try to reorganize your application class into a separate class library? Maybe it is a locking issue.
UPDATE
The steps I did in VB.NET VS2013 in order to make it happen:
Public Class CustomApplication Inherits System.Windows.Application End Class
<self:CustomApplication x:Class="Application" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:self="clr-namespace:WPFVBTest" StartupUri="MainWindow.xaml"> </self:CustomApplication>
Class Application Inherits CustomApplication End Class
Partial Class Application Inherits CustomApplication
This way the application builds and runs without a problem. I hope it helps you to solve your error.
Upvotes: 2
Reputation: 816
I know it's not going to be a popular answer, but... why don't you just upgrade to Visual Studio 2015? Its free!
Hell, they announced VS 2017 just yesterday; also free.
Upvotes: 1
Reputation: 27055
Applications usually points to a Window and tries to get this information from the xaml file; but you have a reference in your xaml file that Visual Studio cannot determine..
xmlns:src="clr-namespace:MyApplication;assembly=WpfTestApplication"
So VS cannot parse your xaml file, and thus gives that error...
My suggestion: override the Window, or use extensions on Application, like so :
public static class ApplicationExtensions
{
public static string GetAwesomeName(this Application)
{
return "I am an awesome application";
}
}
Use it like this:
Application.Current.GetAwesomeName();
Upvotes: -1