Skip to content

Commit bb7b734

Browse files
Merge pull request #815 from AvaloniaUI/luke-get-started-zh-translations
Luke get started zh translations
2 parents 1e1f7ee + d073f2d commit bb7b734

File tree

16 files changed

+993
-12
lines changed

16 files changed

+993
-12
lines changed

docs/get-started/starter-tutorial/adding-a-control.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ description: How to add a button to your temperature converter app. Part 2 of 7
77
import CalculateButtonLeft from '/img/get-started/calculate-button-left.png';
88
import CalculateButtonCenter from '/img/get-started/calculate-button-center.png';
99

10-
1110
# Adding a control
1211

1312
The first step for our temperature converter app is to add a **control**. By “controls”, we mean UI elements that allow interaction with your app. Some examples of controls are buttons, sliders, checkboxes or menus.
@@ -58,4 +57,4 @@ Your **Calculate** button is currently aligned against the left edge of the wind
5857

5958
<Image light={CalculateButtonCenter} alt="A screenshot of an app running in a window, with the button aligned center." maxWidth={400} cornerRadius="true" margin="0,0,30,0"/>
6059

61-
On the next page of this tutorial, you will learn how to add multiple elements to your app using layout controls.
60+
On the next page of this tutorial, you will learn how to add multiple elements to your app using layout controls.

docs/get-started/starter-tutorial/adding-some-layout.mdx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ We can use the `StackPanel` layout control to place some text above the button.
5252

5353
<Image light={TemperatureConverterTextOnly} alt="A screenshot showing a work-in-progress app, with text above a button." position="center" maxWidth={400} cornerRadius="true" margin="0,0,30,0"/>
5454

55-
5655
4. Enclose the `TextBlock` with a `<Border>...</Border>` tag. Set the attributes of the `Border` as follows:
5756

5857
- `Margin="5"`
@@ -113,7 +112,6 @@ We have specified some attributes for the `Grid`:
113112

114113
<Image light={TemperatureConverterEmptyGrid} alt="A screenshot showing a work-in-progress app, with a title, a dotted line, and a button." position="center" maxWidth={400} cornerRadius="true"/>
115114

116-
117115
## Inserting controls in the grid
118116

119117
1. Insert `TextBlock` controls in the left cells of the grid, using the `Grid.Row` and `Grid.Column` attributes to assign the target cells. Use these text blocks to fill the cells with the text “Celsius” and “Fahrenheit”.
@@ -146,8 +144,6 @@ The first cell in a row or column of a `Grid` is numbered 0.
146144

147145
3. Run the app or check the previewer. You should see your text and input boxes added to the window, within the cells marked by the gridlines.
148146

149-
150147
<Image light={TemperatureConverterFilledGrid} alt="A screenshot showing a work-in-progress app, with a title, input boxes in a grid, and a button." position="center" maxWidth={400} cornerRadius="true" margin="10,0,30,0"/>
151148

152-
153149
On the next page of this tutorial, you will learn how to adjust the size of the app window.

docs/get-started/starter-tutorial/customizing-the-avalonia-window.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,4 @@ Height="450">
8989
Most mobile platforms actually ignore window sizes and automatically resize windows to fit the screen. When developing, you won’t literally need to set a separate size for each target platform.
9090
:::
9191

92-
On the next page of this tutorial, you will learn how to create event handling so that the button responds to clicks.
92+
On the next page of this tutorial, you will learn how to create event handling so that the button responds to clicks.

docs/get-started/starter-tutorial/establishing-events-and-responses.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ To verify we’ve created the event handler correctly, we can check the debug ou
7878

7979
<Image light={RiderRunDebugMode} alt="A screenshot showing the location of the button to run a project in debug mode in Rider." position="center" maxWidth={400} cornerRadius="true"/>
8080

81-
8281
2. Open the **Debug Output** tab in the bottom panel.
8382
3. In the running app window, click the **Calculate** button a few times.
8483
4. You should see “Click!” being printed in the debug output in Rider.

docs/get-started/starter-tutorial/exercises.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,14 @@ Make **GetStartedApp** calculate the temperature conversion as the user types.
9292
```xml
9393
<TextBox Grid.Row="0" Grid.Column="1" Margin="0 5" Text="0" TextChanged="Celsius_TextChanged" Name="Celsius"/>
9494
```
95+
9596
2. In **MainWindow.axaml**, delete the entire line starting `<Button>`. It is no longer needed.
9697

9798
~~`<Button HorizontalAlignment="Center" Click="Button_OnClick">Calculate</Button>`~~
9899

99100
3. In **MainWindow.axaml.cs**, locate the event handler line starting `private void`. Change the event name from `Button_OnClick` to whatever you named it in the XAML file, e.g. `Celsius_TextChanged`.
100101

101-
```xml
102+
```csharp
102103
private void Celsius_TextChanged(object? sender, RoutedEventArgs e)
103104
```
104105

docs/get-started/starter-tutorial/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ In the **Views** folder of your project directory, open the file **MainWindow.ax
3838

3939
Nearly everything in **MainWindow.axaml** goes between the `<Window>...</Window>` XAML tag. This tag represents the Avalonia window, where your app will run on the target platform. We’ll look at Avalonia windows in more detail later, when we get to [customizing the Avalonia window](/docs/get-started/starter-tutorial/customizing-the-avalonia-window).
4040

41-
Proceed to the next page of this tutorial to learn how to add a button to the app.
41+
Proceed to the next page of this tutorial to learn how to add a button to the app.

docs/get-started/xaml-previewers.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ If you are new to developing with IDEs, here's how to enable the XAML previewer
1818

1919
<Tabs groupId="ide">
2020
<TabItem value="rider" label="Rider">
21-
1. In Rider, select a **.axaml** file from the top ribbon.
21+
1. In Rider, select a **.axaml** file from the top ribbon.
2222
2. On the right side of the top ribbon, click **Editor and Preview**.
2323
3. Build your project.
2424

@@ -52,4 +52,4 @@ If you are new to developing with IDEs, here's how to enable the XAML previewer
5252

5353
:::tip
5454
If the previewer is unresponsive to your changes, try building the project again.
55-
:::
55+
:::
Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
---
2+
id: index
3+
title: 入门指南
4+
description: 开始使用 Avalonia。安装 Avalonia 及其先决条件,然后使用 Avalonia 模板启动您的第一个项目。
5+
---
6+
import DownloadAvaloniaRider from '/img/get-started/download-rider-avaloniarider.png';
7+
import DownloadAvaloniaExtensionForVS from '/img/get-started/download-vs-avalonia-extension.png';
8+
import WelcomeToAvalonia from '/img/get-started/welcome-to-avalonia.png';
9+
10+
import useBaseUrl from '@docusaurus/useBaseUrl';
11+
12+
# 入门指南
13+
14+
让我们开始使用 Avalonia。本指南将带您完成安装 Avalonia 并在集成开发环境 (IDE) 中启动第一个项目的过程。
15+
16+
## 先决条件
17+
18+
您必须已安装:
19+
20+
- .NET(8.0 或更高版本,截至 2025 年 10 月)
21+
- 您选择的 IDE(我们推荐 JetBrains Rider 或 Visual Studio)
22+
23+
### 安装 .NET
24+
25+
[.NET 官网](https://dotnet.microsoft.com/en-us/download/dotnet)下载,然后按照安装说明进行操作。
26+
27+
### 选择 IDE
28+
29+
Avalonia 在 Visual Studio 或 JetBrains Rider 中效果最佳。
30+
31+
Visual Studio Code 也受支持,但由于功能较为有限,我们不推荐使用。
32+
33+
<Tabs groupId="ide">
34+
<TabItem value="rider" label="Rider">
35+
如果您使用 macOS 或 Linux,我们推荐使用 [JetBrains Rider](https://www.jetbrains.com/rider/)。JetBrains Rider 在这些操作系统上提供完整、成熟的开发体验,包括对 XAML 的内置支持。
36+
37+
建议安装第三方插件 [AvaloniaRider](https://plugins.jetbrains.com/plugin/14839-avaloniarider),该插件可在您工作时实时预览 XAML。
38+
39+
安装 AvaloniaRider:
40+
41+
1. 在 JetBrains Rider 中,转到**设置 → 插件**
42+
2. 转到**市场**选项卡。
43+
3. 在搜索栏中输入"AvaloniaRider"。
44+
4. 点击**安装**
45+
5. 按照任何其他安装说明进行操作。您可能需要关闭并重新打开 JetBrains Rider 以完成安装。
46+
47+
<div className="center" style={{maxWidth:400}}>
48+
<img className="center" src={DownloadAvaloniaRider} alt="显示如何在 Rider 中下载 AvaloniaRider 扩展的屏幕截图。" />
49+
</div>
50+
51+
有关使用 XAML 预览器的更多信息,请参阅 [XAML 预览器](/docs/get-started/xaml-previewers)页面。
52+
</TabItem>
53+
<TabItem value="vs" label="Visual Studio">
54+
如果您在 Windows 上工作,可以使用 [Visual Studio](https://visualstudio.microsoft.com/) 及其 Avalonia for Visual Studio 扩展。
55+
56+
安装 Avalonia for Visual Studio:
57+
58+
1. 在 Visual Studio 中,转到**扩展 → 管理扩展**
59+
2. 在搜索栏中输入"Avalonia"。
60+
3. 点击**安装**
61+
4. 按照任何其他安装说明进行操作。您可能需要关闭并重新打开 Visual Studio 以完成安装。
62+
63+
<div className="center" style={{maxWidth:400}}>
64+
<img className="center" src={DownloadAvaloniaExtensionForVS} alt="显示如何在 Visual Studio 中下载 Avalonia 扩展的屏幕截图。" />
65+
</div>
66+
67+
或者,您可以[从 Visual Studio Marketplace 下载该扩展](https://marketplace.visualstudio.com/items?itemName=AvaloniaTeam.AvaloniaVS)
68+
69+
:::note
70+
如果您使用的是较旧版本的 Visual Studio,可能需要从 Marketplace 下载较旧版本的扩展,例如 [2019 版本](https://marketplace.visualstudio.com/items?itemName=AvaloniaTeam.AvaloniaforVisualStudio)
71+
:::
72+
73+
有关使用 XAML 预览器的更多信息,请参阅 [XAML 预览器](/docs/get-started/xaml-previewers)页面。
74+
</TabItem>
75+
<TabItem value="vsc" label="Visual Studio Code">
76+
如果您更喜欢使用 [Visual Studio Code](https://code.visualstudio.com/),Avalonia for VSCode 扩展提供基本功能,如自动完成和预览器。您可以[从 Visual Studio Code Marketplace 下载该扩展](https://marketplace.visualstudio.com/items?itemName=AvaloniaTeam.vscode-avalonia)
77+
78+
由于支持有限,我们不推荐使用 Visual Studio Code。
79+
</TabItem>
80+
</Tabs>
81+
82+
## 安装 Avalonia 模板
83+
84+
根据您使用的 IDE,您可能已经安装了 [Avalonia 模板](https://github.com/AvaloniaUI/avalonia-dotnet-templates)。使用 Avalonia for Visual Studio 扩展的 Visual Studio 就是这种情况。
85+
86+
您可以运行此命令来检查有哪些可用的 .NET 模板:
87+
88+
```
89+
dotnet new list
90+
```
91+
92+
在其他 .NET 模板中查找这些 Avalonia 模板:
93+
94+
```
95+
Template Name Short Name Language Tags
96+
-------------------------------------------- -------------------------- ---------- ---------------------------------------------------------
97+
Avalonia .NET App avalonia.app [C#],F# Desktop/Xaml/Avalonia/Windows/Linux/macOS
98+
Avalonia .NET MVVM App avalonia.mvvm [C#],F# Desktop/Xaml/Avalonia/Windows/Linux/macOS
99+
Avalonia Cross Platform Application avalonia.xplat [C#],F# Desktop/Xaml/Avalonia/Browser/Mobile
100+
```
101+
102+
如果您在列表中没有看到这些模板,可以运行此命令来安装它们:
103+
104+
```
105+
dotnet new install Avalonia.Templates
106+
```
107+
108+
检查输出。您应该会看到这些模板已安装:
109+
110+
```
111+
Template Name Short Name Language Tags
112+
-------------------------------------------- -------------------------- ---------- ---------------------------------------------------------
113+
Avalonia .NET App avalonia.app [C#],F# Desktop/Xaml/Avalonia/Windows/Linux/macOS
114+
Avalonia .NET MVVM App avalonia.app [C#],F# Desktop/Xaml/Avalonia/Windows/Linux/macOS
115+
Avalonia Cross Platform Application avalonia.xplat [C#],F# Desktop/Xaml/Avalonia/Web/Mobile
116+
Avalonia Resource Dictionary avalonia.resource Desktop/Xaml/Avalonia/Windows/Linux/macOS
117+
Avalonia Styles avalonia.styles Desktop/Xaml/Avalonia/Windows/Linux/macOS
118+
Avalonia TemplatedControl avalonia.templatedcontrol [C#],F# Desktop/Xaml/Avalonia/Windows/Linux/macOS
119+
Avalonia UserControl avalonia.usercontrol [C#],F# Desktop/Xaml/Avalonia/Windows/Linux/macOS
120+
Avalonia Window avalonia.window [C#],F# Desktop/Xaml/Avalonia/Windows/Linux/macOS
121+
```
122+
123+
### 安装故障排除
124+
125+
#### .NET 不是已识别的程序
126+
127+
首先,确保已安装 .NET SDK。运行此命令:
128+
129+
```
130+
dotnet --list-sdks
131+
```
132+
133+
如果正确安装了 .NET SDK,将返回类似以下的输出:
134+
135+
```
136+
8.0.202 [C:\Program Files\dotnet\sdk]
137+
```
138+
139+
如果终端继续报告缺少 .NET,请尝试重新启动终端。
140+
141+
#### 找不到 `Avalonia.Templates`
142+
143+
确保 NuGet 已正确设置。运行此命令:
144+
145+
```
146+
dotnet nuget list source
147+
```
148+
149+
检查输出是否显示以下内容作为已注册的源:
150+
151+
```
152+
nuget.org [Enabled]
153+
https://api.nuget.org/v3/index.json
154+
```
155+
156+
如果未列出此源,请使用此命令添加它:
157+
158+
```
159+
dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org
160+
```
161+
162+
如果即使 NuGet 已列为已注册源,包安装仍然失败,请检查您的网络连接或防火墙设置。
163+
164+
## 创建您的第一个项目
165+
166+
您的第一个项目将使用 MVVM 模板。
167+
168+
<Tabs groupId="ide">
169+
<TabItem value="rider" label="Rider">
170+
1. 在 Rider 启动屏幕上,选择**新建解决方案**
171+
2. 在侧边栏中,向下滚动到"自定义模板"。选择 **Avalonia .NET MVVM App**
172+
3. 将您的解决方案命名为"GetStartedApp"。
173+
4. 点击**创建**
174+
</TabItem>
175+
<TabItem value="vs" label="Visual Studio">
176+
1. 在 Visual Studio 中,点击**文件 → 新建 → 项目/解决方案**
177+
2. 在搜索框中输入"Avalonia"。
178+
3. 从搜索结果中选择 **Avalonia .NET MVVM App**。如果 Visual Studio 提供多个选项,请选择 **C#** 的选项。然后点击**下一步**
179+
4. 将您的项目命名为"GetStartedApp"。
180+
5. 如果需要,更改目标目录。然后点击**下一步**
181+
6. 选择您首选的 **.NET** 版本作为框架。
182+
7. 如果有选择目标平台的选项,选择**桌面**
183+
8. 点击**创建**
184+
</TabItem>
185+
<TabItem value="vsc" label="Visual Studio Code">
186+
1. 在 Visual Studio Code 中,调出命令面板。在 Windows 上为 Ctrl + Shift + P,在 macOS 上为 Cmd + Shift + P。
187+
2. 在搜索中输入".NET"。
188+
3. 从搜索结果中选择 **.NET: New Project...**
189+
4. 从项目模板列表中选择 **Avalonia MVVM App**
190+
5. 为项目指定设备上的目录。
191+
6. 将您的项目命名为"GetStartedApp"。
192+
7. 点击**创建项目**
193+
</TabItem>
194+
<TabItem value="cli" label="命令行">
195+
1. 在命令行中运行此命令:
196+
197+
```
198+
dotnet new avalonia.mvvm -o GetStartedApp
199+
```
200+
201+
2. 检查您的设备上是否有一个名为 **GetStartedApp** 的新文件夹,其中包含新的项目文件。
202+
</TabItem>
203+
</Tabs>
204+
205+
## 运行您的项目
206+
<Tabs groupId="ide">
207+
<TabItem value="rider" label="Rider">
208+
点击顶部工具栏中的**运行**
209+
210+
解决方案将构建并在新窗口中运行您的应用程序。默认情况下,会显示字符串"Welcome to Avalonia!"
211+
</TabItem>
212+
<TabItem value="vs" label="Visual Studio">
213+
在顶部工具栏中,选择**运行**按钮旁边的"GetStartedApp"。然后点击**运行**
214+
215+
解决方案将构建并在新窗口中运行您的应用程序。默认情况下,会显示字符串"Welcome to Avalonia!"
216+
</TabItem>
217+
<TabItem value="vsc" label="Visual Studio Code">
218+
1. 在侧边导航栏中选择**运行和调试**
219+
2. 如果提示选择调试器,选择 **C#**
220+
3. 点击**运行和调试**
221+
222+
解决方案将构建并在新窗口中运行您的应用程序。默认情况下,会显示字符串"Welcome to Avalonia!"
223+
</TabItem>
224+
<TabItem value="cli" label="命令行">
225+
1. 导航到包含您的 **GetStartedApp** 项目的目录。
226+
2. 运行命令 `dotnet run`
227+
228+
解决方案将构建并在新窗口中运行您的应用程序。默认情况下,会显示字符串"Welcome to Avalonia!"
229+
</TabItem>
230+
</Tabs>
231+
232+
<div className="center" style={{maxWidth:400}}>
233+
<img className="center" src={WelcomeToAvalonia} alt="在窗口中运行的默认 Avalonia 应用程序的屏幕截图。" />
234+
</div>
235+
236+
## 后续步骤
237+
238+
您现在已经在设备上安装了 Avalonia,并知道如何创建和运行 Avalonia 项目。
239+
240+
您可以立即开始开发应用程序。
241+
242+
或者,如果想要一个简短的教程,构建一个简单的应用程序,介绍 Avalonia 中的基本概念和功能,请继续阅读下一页:
243+
244+
<br />
245+
<div style={{ display: 'flex', justifyContent: 'center', gap: '10px' }}>
246+
<Button label="入门教程:构建温度转换器应用程序 →" link="/docs/get-started/starter-tutorial" variant="primary" outline />
247+
</div>

0 commit comments

Comments
 (0)