Skip to content

Commit bc5ddc9

Browse files
Merge pull request #415 from AvaloniaUI/issue-413
Rework Get Started for accuracy
2 parents 0fa2c7e + 631b1fe commit bc5ddc9

File tree

16 files changed

+229
-157
lines changed

16 files changed

+229
-157
lines changed

docs/get-started/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
s---
1+
---
22
id: getting-started
33
title: Starting with the CLI
44
---

docs/get-started/install.md

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@ id: install
33
title: Install
44
---
55

6+
## Preinstallation
7+
8+
Please start with the supported IDE of your choice installed. Avalonia supports Visual Studio, Rider, and Visual Studio
9+
Code.
10+
611
## Install Avalonia UI Templates
712

8-
The best place to get started with Avalonia is by creating an application using a template.
13+
The best way to get started with Avalonia is by creating an application using a project template.
914

10-
To install the Avalonia templates, run the following command:
15+
To install the [Avalonia templates](https://github.com/AvaloniaUI/avalonia-dotnet-templates), run the following command:
1116

1217
```bash
1318
dotnet new install Avalonia.Templates
@@ -36,4 +41,56 @@ Avalonia Styles avalonia.styles
3641
Avalonia TemplatedControl avalonia.templatedcontrol [C#],F# Desktop/Xaml/Avalonia/Windows/Linux/macOS
3742
Avalonia UserControl avalonia.usercontrol [C#],F# Desktop/Xaml/Avalonia/Windows/Linux/macOS
3843
Avalonia Window avalonia.window [C#],F# Desktop/Xaml/Avalonia/Windows/Linux/macOS
39-
```
44+
```
45+
46+
## Create a new Application
47+
48+
Once the project templates are installed, you can create a new _Avalonia UI_ application from CLI by running the following command:
49+
50+
```bash
51+
dotnet new avalonia.app -o MyApp
52+
```
53+
54+
This will create a new folder called `MyApp` containing your application files. To run the application, navigate to the `MyApp` folder and run:
55+
56+
```bash
57+
cd MyApp
58+
dotnet run
59+
```
60+
61+
The project templates will also allow for project creation from your IDE.
62+
63+
## Installation Troubleshooting
64+
65+
### Ensure .NET SDK is installed
66+
67+
```
68+
dotnet --list-sdks
69+
70+
8.0.202 [C:\Program Files\dotnet\sdk] <-- Your version may vary
71+
```
72+
73+
If `dotnet` is not a recognized program, then ensure you've installed your IDE first. Next, ensure that `dotnet` is
74+
associated with the terminal. On Windows, this involves checking environment variables: `echo %PATH%` in the command prompt or
75+
`echo $Env:PATH` in PowerShell.
76+
77+
### Ensure NuGet source is correct
78+
79+
If while installing the project templates, you receive an error stating the `Avalonia.Templates` package cannot be found,
80+
then ensure NuGet is correctly setup with .NET's standard global package source.
81+
82+
```
83+
dotnet nuget list source
84+
85+
Registered Sources:
86+
1. nuget.org [Enabled]
87+
https://api.nuget.org/v3/index.json
88+
```
89+
90+
If this source is not listed, add it:
91+
92+
```
93+
dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org
94+
```
95+
96+
If the package install still fails despite NuGet being listed, then suspect a network connectivity or firewall issue.

docs/get-started/set-up-an-editor.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,26 @@ import AvaloniaVsExtensionNuGetScreenshot from '/img/get-started/avalonia-vs-ext
88

99
# Set Up an Editor
1010

11-
You can create an Avalonia application using any code editor, but using an IDE will give you support for authoring Avalonia XAML files with a previewer and code completion.
11+
You can create an Avalonia application using any code editor, but using an IDE will give you support for authoring
12+
Avalonia XAML files with a previewer and code completion.
1213

1314
## JetBrains Rider
1415

15-
The [JetBrains Rider](https://www.jetbrains.com/rider/) IDE has built-in support for Avalonia XAML [starting in 2020.3](https://www.jetbrains.com/rider/whatsnew/2020-3/#version-2020-3-avalonia-support) including first-class support for Avalonia-specific XAML features and custom code inspections.
16+
The [JetBrains Rider](https://www.jetbrains.com/rider/) IDE has built-in support for Avalonia XAML [starting in 2020.3](https://www.jetbrains.com/rider/whatsnew/2020-3/#version-2020-3-avalonia-support) including first-class
17+
support for Avalonia-specific XAML features and custom code inspections.
1618

1719
See the [JetBrains Rider 2020.3 release announcement](https://www.jetbrains.com/rider/whatsnew/2020-3/#version-2020-3-avalonia-support) for more information.
1820

19-
Rider does not yet provide a visual designer, but this is in development. See [the GitHub project](https://github.com/ForNeVeR/AvaloniaRider) for more information and instructions on how to install.
21+
Rider does not yet provide a visual designer, but this is in development. See [the GitHub project](https://github.com/ForNeVeR/AvaloniaRider) for more
22+
information and instructions on how to install.
2023

2124
## Visual Studio
2225

2326
If you're developing Avalonia with Visual Studio you should install the [Avalonia for Visual Studio](https://marketplace.visualstudio.com/items?itemName=AvaloniaTeam.AvaloniaVS) extension.
2427

2528
<img className="center" src={AvaloniaVsExtensionMarketplaceScreenshot} alt="" />
2629

27-
The extension provides intellisense support for Avalonia XAML together with a previewer.
30+
The extension provides IntelliSense support for Avalonia XAML together with a previewer.
2831

2932
To install the Avalonia for Visual Studio extension:
3033

docs/get-started/test-drive/add-a-control.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,38 @@ import Highlight from '@site/src/components/Highlight';
77
import CalculateButton from '/img/get-started/test-drive/calculate-button.png';
88
import ButtonIntellisenseScreenshot from '/img/get-started/test-drive/button-intellisense.png';
99

10-
So far the main window of your application displays only a text string. On this page, you will learn how to add some of the built-in controls that are part of Avalonia.
10+
So far, the main window of your application displays only a text string. On this page, you will learn how to add some of the built-in controls that are part of Avalonia.
1111

1212
## Button
1313

14-
Avalonia contains a built-in control that creates a button. Follow this procedure to replace the text string you currently have in the content zone of the window, with a button control.
14+
Avalonia contains a built-in control that creates a button. Follow this procedure to replace the text string currently in the `Window`'s content zone with a button control.
1515

1616
- Stop the app if it is running.
1717
- Locate the
1818
`<TextBlock Text="text" HorizontalAlignment="Center" VerticalAlignment="Center"/>`
1919
in the `MainView.axaml` file..
2020
- Delete the entire line.
21-
- Insert a 'Button' tag as shown:
21+
- Insert a `Button` tag as shown:
2222
```xml
2323
<Button>Calculate</Button>
2424
```
2525
<img className="center" src={CalculateButton} alt="" />
2626

2727
:::tip
28-
If you're using a previewer, you will see the button appear in the preview pane as soon as the XAML is valid. You can also try out a mouse move-over and click on the button to see the different colors it displays in different states.
28+
If you're using the previewer, you will see the button appear in the preview pane as soon as the XAML is valid. You can
29+
also try hovering and clicking the `Button` to see it change appearance in different states.
2930
:::
3031

3132
- Run the app to confirm that the presentation and behaviour of the button is the same at runtime.
3233

3334
## Control Attributes
3435

35-
The XAML code for Avalonia controls uses attributes to specify presentation and behaviour. The attributes can set properties, call methods and event handlers in the controls created by the XAML.
36+
XAML uses XML attributes to specify presentation and behavior for controls. These attributes can set properties, call
37+
methods, and call event handlers in the controls created by the XAML.
3638

37-
For example, you will notice that the button you just implemented is rendered hard against the left edge of the window. This is a result of the default value of its horizontal alignment property (which is left). Follow this procedure to set the horizontal alignment to centered instead.
39+
For example, the `Button` is currently positioned hard against the left edge of the `Window`. This is a result
40+
of the default value (left) of its `HorizontalAlignment` property. Follow this
41+
procedure to set the `HorizontalAlignment` to centered instead.
3842

3943
- Add a new attribute to the Button tag as follows:
4044

@@ -43,12 +47,13 @@ For example, you will notice that the button you just implemented is rendered h
4347
```
4448

4549
:::tip
46-
If you're using an IDE, notice how the Avalonia Intellisense guides you as you add attributes to the XAML.
50+
If you're using an IDE, notice how the Avalonia code completion guides you as you add attributes to the XAML.
4751

4852
<img className="center" src={ButtonIntellisenseScreenshot} alt="" />
4953
:::
5054

51-
The button should now move to the center of the window content zone (both horizontally and vertically).
55+
The `Button` should now move to the center of the window content zone. Horizontally because of the change and vertically
56+
because of the Button's default.
5257

5358
:::info
5459
For full information about the complete range of Avalonia UI built-in controls, and their attributes, see the reference section [here](../../reference/controls).

docs/get-started/test-drive/add-some-layout.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@ title: Add Some Layout
66
import StackPanelZonesDiagram from '/img/get-started/test-drive/stackpanel-zones.png';
77
import TemperatureStackPanelScreenshot from '/img/get-started/test-drive/temperature-stackpanel.png';
88

9-
Avalonia provides a range of built-in controls to help you layout the visual elements of an application. On this page you will see how to use some of these layout controls.
9+
Avalonia provides a range of built-in controls to help you layout the visual elements of an application. On this page,
10+
you will see how to use some of these layout controls.
1011

1112
At this stage, your application has a single button located in the content zone of the main window.
1213

13-
In fact an Avalonia window allows only a single other control in its content zone. So to add the multiple visual elements required for most applications, you will need to use one of the built-in layout controls that allows multiple other controls inside its content zone.
14+
In fact, an Avalonia `Window` allows only one control in its content zone. To show multiple visual elements, you
15+
must use a layout control that allows multiple controls within its content zone.
1416

15-
## Stack Panel
17+
## StackPanel
1618

17-
The stack panel control allows multiple controls in its content zone, and arranges them in a vertical stack in the sequence they are defined in the XAML.
19+
The `StackPanel` control lays out a sequence of controls in the order they are defined in XAML. By default, it lays out
20+
in a vertical stack but this can be changed to horizontal with its `Orientation` property.
1821

1922
<img src={StackPanelZonesDiagram} alt="" />
2023

@@ -25,33 +28,30 @@ The stack panel control allows multiple controls in its content zone, and arrang
2528
</StackPanel>
2629
```
2730

28-
## Text Block
31+
## TextBlock
2932

30-
The text block control gives you full control over the styling of the text it contains.
33+
The `TextBlock` control allows extensive styling of its contained text.
3134

32-
To take the example forwards, add a stack panel as follows (you can include the existing the button XAML).
35+
To take the example forward, add a `StackPanel` as follows (include the preexisting `Button` XAML):
3336

3437
```xml
3538
<StackPanel>
36-
<Border Margin="5"
37-
CornerRadius="10"
38-
Background="LightBlue">
39-
<TextBlock Margin="5"
40-
FontSize="24"
41-
HorizontalAlignment="Center"
42-
Text="Temperature Converter">
43-
</TextBlock>
39+
<Border Margin="5" CornerRadius="10" Background="LightBlue">
40+
<TextBlock Margin="5"
41+
FontSize="24"
42+
HorizontalAlignment="Center"
43+
Text="Temperature Converter">
44+
</TextBlock>
4445
</Border>
45-
<StackPanel>
46-
</StackPanel>
46+
4747
<Button HorizontalAlignment="Center">Calculate</Button>
48-
</StackPanel>
48+
</StackPanel>
4949
```
5050

5151
<img className="center" src={TemperatureStackPanelScreenshot} alt="" />
5252

5353
:::info
54-
You can explore the other layout controls in Avalonia from the reference [here](../../reference/controls/layout-controls.md).
54+
You can explore the other layout controls in Avalonia using the reference [here](../../reference/controls/layout-controls.md).
5555
:::
5656

5757
On the next page, you will add some inputs to the middle of the window.

docs/get-started/test-drive/code-with-controls.md

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@ id: code-with-controls
33
title: Code With Controls
44
---
55

6-
import Highlight from '@site/src/components/Highlight';
7-
8-
The action you will implement here is to update the Fahrenheit temperature control, using the value of the `celsius` control, and a simple formula, whenever the button is clicked.
6+
In this section, you will implement the core logic to update the Fahrenheit temperature based on the Celsius input.
97

108
## Control Names
119

12-
When Avalonia creates the main window at runtime, it also creates objects for each of the controls defined in the window. Your code can access the controls at runtime, but to access them, it will need some control names.
10+
Avalonia creates objects for each control defined in the XAML hierarchy. Your code can access these controls at runtime,
11+
but should be named for easy access.
1312

14-
To add some control names, follow this procedure:
13+
To add control names, follow this procedure:
1514

1615
- Stop the app if it is running.
1716
- Locate the `TextBox` for Celsius.
18-
- Add the name attribute like this:
17+
- Add the `Name` attribute like this:
1918

2019
```xml
2120
<TextBox ... Name="celsius"/>
@@ -27,11 +26,11 @@ To add some control names, follow this procedure:
2726
<TextBox ... Name="fahrenheit"/>
2827
```
2928

30-
## Get Control Values in Code-behind
29+
## Get Control Values in Code-Behind
3130

32-
To demonstrate access to the text value of the `celsius` input, follow this procedure:
31+
To access the `Text` value of the `celsius` input, follow this procedure:
3332

34-
- Switch to the **MainWindow.axaml.cs** code-behind file.
33+
- Switch to the **MainView.axaml.cs** code-behind file.
3534
- Locate the `ButtonClicked` event handler.
3635
- Alter the `Debug` statement to display the text property of the `celsius` input, like this:
3736

@@ -41,9 +40,10 @@ Debug.WriteLine($"Click! Celsius={celsius.Text}");
4140

4241
- Run the app to confirm that you can see the value in the Celsius appear in the debug window.
4342

44-
## Set Control Values in Code-behind
43+
## Set Control Values in Code-Behind
4544

46-
To use the simple formula that converts Celsius temperature to Fahrenheit, you will first need to ensure that the Celsius input text converts to a number. The formula is then:
45+
To use the simple formula that converts Celsius temperature to Fahrenheit, you will first need to ensure that the
46+
Celsius input text converts to a number. The formula is then:
4747

4848
```
4949
Tf = Tc * (9/5) + 32
@@ -52,43 +52,47 @@ Tf = Tc * (9/5) + 32
5252
To add the conversion formula, follow this procedure:
5353

5454
- Locate the `ButtonClicked` event handler.
55-
- Alter the code in the event handler to check that the Celsius input text converts to a number.
56-
- Alter the code to include the conversion formula.
57-
- Update the text in the Fahrenheit input to the result of the conversion formula.
55+
- Validate the Celsius input text as a number.
56+
- Use the conversion formula.
57+
- Update the `Text` in the Fahrenheit input.
5858
- Run the app to check your work.
5959

6060
One implementation of the above is as follows:
6161

6262
```csharp
63-
if (Double.TryParse(celsius.Text, out double C))
64-
{
65-
var F = C * (9d / 5d) + 32;
66-
fahrenheit.Text = F.ToString("0.0");
67-
}
68-
else
63+
public void ButtonClicked(object source, RoutedEventArgs args)
6964
{
70-
celsius.Text = "0";
71-
fahrenheit.Text = "0";
65+
if (Double.TryParse(celsius.Text, out double C))
66+
{
67+
var F = C * (9d / 5d) + 32;
68+
fahrenheit.Text = F.ToString("0.0");
69+
}
70+
else
71+
{
72+
celsius.Text = "0";
73+
fahrenheit.Text = "0";
74+
}
7275
}
7376
```
7477

7578
You can check your work using the following conversion table:
7679

77-
| Celsius | Farenheit |
78-
| ---------- | --------- |
79-
| -10 | 14.0 |
80-
| 0 | 32.0 |
81-
| 10 | 50.0 |
82-
| 21 | 69.8 |
83-
| 25 | 77.0 |
84-
| 32 | 89.6 |
80+
| Celsius | Fahrenheit |
81+
|---------|------------|
82+
| -10 | 14.0 |
83+
| 0 | 32.0 |
84+
| 10 | 50.0 |
85+
| 21 | 69.8 |
86+
| 25 | 77.0 |
87+
| 32 | 89.6 |
8588

8689
### Exercises
8790

88-
- You have now used an event handler to get and set control properties at runtime. You could now try some of these exercises:
91+
You have now used an event handler to get and set control properties at runtime. Try some of these exercises:
92+
8993
- Stop showing the gridlines (easy).
90-
- Stop the user changing the text in the Fahrenheit input by setting the `IsReadOnly` attribute (easy).
91-
- Calculate the conversion as the user types into the Celsius input (moderate).
94+
- Stop the user from changing the text in the Fahrenheit input by setting the `IsReadOnly` attribute (easy).
95+
- Calculate the conversion as the user types into the Celsius input using the `TextChanged` event (moderate).
9296

9397
:::info
9498
For full information about the complete range of Avalonia built-in controls, events and attributes, see the controls reference section [here](../../reference/controls/).

docs/get-started/test-drive/create-a-project.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dotnet new install Avalonia.Templates
2525

2626
To get started, we're going to use the MVVM Avalonia template: `Avalonia MVVM Application` (or `avalonia.mvvm` in the CLI).
2727

28-
<Tabs>
28+
<Tabs groupId="ide">
2929
<TabItem value="cli" label="Command Line" default>
3030
Run the command:
3131

@@ -75,7 +75,7 @@ The template will create a new solution and two new projects. `GetStartedApp` is
7575

7676
We're now ready to run the project!
7777

78-
<Tabs>
78+
<Tabs groupId="ide">
7979
<TabItem value="cli" label="Command Line" default>
8080
Go into the `GetStartedApp` directory and run:
8181

0 commit comments

Comments
 (0)