Completely removed "App.xaml" and created your own entry point. What are the implications?

I just removed “App.xaml” entirely from my solution and created my own xamlless input class, where I implement the traditional static Main() method.

I launch a new Application class and configure it before calling its Run() method, providing it with StartupUri and also adding a new resource dictionary to it so that my styles are applied automatically. Everything works as intended, the main window is displayed, resources are loaded, and templates are correctly applied for all controls and windows.

But I need to know if there are any bad consequences if you do this? What did the App class offer me, so I have to save it instead of replacing it with my own compact and xamlless entry point, which gave me the exact same result?

 public static class Entry { private static readonly Application _application = new Application(); [STAThread] public static void Main() { _application.StartupUri = new Uri( "/Eurocentric;component/Interface/MainWindow.xaml" , UriKind.Relative ); var style = new ResourceDictionary { Source = new Uri( "/Eurocentric;component/Interface/Styles/VictorianStyle.xaml", UriKind.Relative ) }; _application.Resources.MergedDictionaries.Add( style ); TemplatedWindow.Defaults(); _application.Run(); } } 
+5
source share
1 answer

A look at the App class in the decompiler shows this auto-generated method in the App class:

 /// <summary> /// Application Entry Point. /// </summary> [System.STAThreadAttribute()] [System.Diagnostics.DebuggerNonUserCodeAttribute()] [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")] public static void Main() { RootNamespace.App app = new RootNamespace.App(); app.InitializeComponent(); app.Run(); } 

So, I would say there is no difference in what happens at runtime. However, this has affected our development experience.

I also used a manual approach, and I saw that ReSharper does not receive application resources, therefore they are not available at the end of the XAML code, and there are a huge number of warnings, because of this. To mitigate this, I had to add a fake App.xaml file to the project. ReSharper specifically searches for the .xaml file using the ApplicationDefinition build action, so you can keep the entry point different to satisfy both ReSharper and the need to use a custom entry point.

One more thing, you can see here that, unlike other .xaml files, the InitializeComponent method is called separately instead of being called in the overriden constructor. Therefore, if you ever decide to use the application class supported by XAML at your user input point, you will either have to call this method separately, or add a constructor override that does this because it is not created by default.

+1
source

All Articles