Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom App class bypassing autogenerated file

Tags:

c#

wpf

When I create Wpf project, I get default App class which is derived from Application.

I want to derive App from my own class (which of course inherits Application), but there is autogenerated App.g.cs file which define that App is derived form Application.

How can I turn off that autogenerated file?

like image 889
Stecya Avatar asked Dec 17 '22 16:12

Stecya


2 Answers

Change the <Application tag in App.xaml to <local:YourClass xmlns:local="clr-namespace:Your.Namespace"

Alternatively, get rid of App.xaml and create the entire class yourself.

like image 181
SLaks Avatar answered Jan 02 '23 16:01

SLaks


When creating your own class derived from Application set the build action to ApplicationDefinition:

"Identifies the XAML markup file that contains the application definition (a XAML markup file whose root element is Application). ApplicationDefinition is mandatory when Install is true and OutputType is winexe. A WPF application and, consequently, an MSBuild project can only have one ApplicationDefinition."

Extract From msdn link

To turn off the creation of the autogenerated app.g.cs change the build action from "ApplicationDefinition" to "Page" and substitute your own entry point into the app.

like image 37
Andrew Avatar answered Jan 02 '23 16:01

Andrew