WPF defines its own Main()
method. How should I go about replacing it with my own Main
method that (normally) opens the WPF MainWindow
(e.g. to add a non-WPF scripting mode via command-line arguments)?
相关问题
- Generic Generics in Managed C++
- VNC control for WPF application
- How to Debug/Register a Permanent WMI Event Which
- 'System.Threading.ThreadAbortException' in
- Bulk update SQL Server C#
相关文章
- .net中MessageBox.Show使用问题
- IdentityServer 报错:"idp claim is missing"
- 在 IdentityServer 中如何给 id token 添加更多信息
- WPF:如何在Trigger里修改Orientation?
- IdentityServer 的 Selector 在哪个 nuget 包
- 使用 IdentityServer 的项目遭遇错误:"IDX20803: Unable to obt
- ASP.NET Core ConfigureServices 中从 appsettings.json
- WPF aforge 怎么做一个 圆形的播放器
Some examples depict changing App.xaml's Build Action from
ApplicationDefinition
toPage
and writing your ownMain()
that instantiates theApp
class and calls itsRun()
method, but this can produce some unwanted consequences in the resolution of application-wide resources in App.xaml.Instead, I suggest making your own
Main()
in its own class and setting the Startup Object to that class in the project properties:I do this to take advantage of some
AppDomain
events that must be subscribed to before anything else happens (such asAssemblyResolve
). The unwanted consequences of setting App.xaml toPage
that I experienced included myUserControl
Views (M-V-VM) not resolving resources held in App.xaml during design-time.Create new class with your custom static Main method. At the end of this method just call original App.Main() generated by WPF:
Then set your project’s “Startup object” setting to the class containing your static Main().
guys The problem is that your program has two static Main() methods, that will cause the compiler to complain between; To resolve this, try one of the following:
Using a custom Main() you might run into problems because StartupUri is not set.
You can use this to set it without headaches in your App class (Don't forget to remove StartupUri from App.xaml and set its Build Action to Page):
Typically I edit
App.xaml
to add this support:The relevant part being I changed from
StartupUri
toStartup
with an event handler inApp.xaml.cs
. Here is an example: