Uno 开源项目教程
1. 项目的目录结构及介绍
Uno 项目的目录结构如下:
Uno/
├── README.md
├── Uno.sln
├── Uno.UI.sln
├── src/
│ ├── Uno.Core/
│ ├── Uno.Foundation/
│ ├── Uno.UI/
│ ├── Uno.Wasm.Bootstrap/
│ ├── Uno.Xaml/
│ └── ...
├── tests/
│ ├── Uno.Core.Tests/
│ ├── Uno.Foundation.Tests/
│ ├── Uno.UI.Tests/
│ └── ...
└── ...
目录结构介绍
README.md
: 项目介绍和基本使用说明。Uno.sln
和Uno.UI.sln
: 项目的解决方案文件,用于在 Visual Studio 中打开和管理项目。src/
: 包含项目的源代码。Uno.Core/
: 核心库。Uno.Foundation/
: 基础库。Uno.UI/
: UI 库。Uno.Wasm.Bootstrap/
: WebAssembly 启动库。Uno.Xaml/
: XAML 支持库。
tests/
: 包含项目的测试代码。Uno.Core.Tests/
: 核心库的测试。Uno.Foundation.Tests/
: 基础库的测试。Uno.UI.Tests/
: UI 库的测试。
2. 项目的启动文件介绍
项目的启动文件主要位于 src/Uno.UI/
目录下,其中 App.xaml
和 App.xaml.cs
是主要的启动文件。
App.xaml
<Application
x:Class="Uno.UI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Uno.UI">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
App.xaml.cs
namespace Uno.UI
{
public partial class App : Application
{
public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
}
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
// 从之前的会话中恢复状态
}
Window.Current.Content = rootFrame;
}
if (e.PrelaunchActivated == false)
{
if (rootFrame.Content == null)
{
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
Window.Current.Activate();
}
}
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
}
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
// 保存应用程序状态并停止任何后台活动
deferral.Complete();
}
}
}
3. 项目的配置文件介绍
项目的配置文件主要位于 src/Uno.UI/
目录下,其中 App.config
和 Uno.UI.csproj
是主要的配置文件。
App.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2