[英]How to manually create an App.xaml file in a WPF Python Project in Visual Studio?
[英]How to add a new app.xaml to WPF project
我編寫了一個用於服務器-客戶端連接的應用程序。 在WPF項目中,有一個具有啟動方法的App.xaml。 我想對App2.xaml執行相同的操作,並復制並更改客戶端UI的名稱+啟動URI App2.xaml中的代碼是這樣的
<Application x:Class="assembly_line_balance_demo_ga_dp_tttn09_2013.App2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="View/MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>
但是,在我重建項目之后,它不會在“屬性”解決方案中顯示新的啟動對象。 由於客戶端和服務器內部共享代碼,因此我需要在一個項目中配置兩個UI並構建為2個不同的應用程序。 請幫忙
我認為每個項目只允許一個App.xaml。
您可以這樣更改“啟動Uri”:
在文件App.xaml上,刪除StartupUri屬性:
<Application x:Class="WpfApplication4.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<!-- StartupUri="MainWindow.xaml" -->
<Application.Resources>
</Application.Resources>
</Application>
在文件App.xaml.cs上
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
// Add this override function
protected override void OnStartup(StartupEventArgs e)
{
if(e.Args.Contains("Client"))
this.StartupUri = new Uri("View/MainWindow.xaml", UriKind.RelativeOrAbsolute);
else
this.StartupUri = new Uri("View/MainWindowServer.xaml", UriKind.RelativeOrAbsolute);
}
}
那你可以打電話
YourApplication.exe Client
要么
YourApplication.exe Server
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.