-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
18fe816
commit de1bcb1
Showing
32 changed files
with
413 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
--- | ||
id: add-some-layout | ||
title: Add Some Layout | ||
--- | ||
|
||
import useBaseUrl from '@docusaurus/useBaseUrl'; | ||
import StackPanelZonesDiagram from '/img/get-started/test-drive/stackpanel-zones.png'; | ||
|
||
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. | ||
|
||
At this stage, your application has a single button located in the content zone of the main window. | ||
|
||
In fact, an Avalonia `Window` allows only one control in its content zone. To show multiple visual elements, you | ||
must use a layout control that allows multiple controls within its content zone. | ||
|
||
## StackPanel | ||
|
||
The `StackPanel` control lays out a sequence of controls in the order they are defined in XAML. By default, it lays out | ||
in a vertical stack but this can be changed to horizontal with its `Orientation` property. | ||
|
||
<img src={StackPanelZonesDiagram} alt="" /> | ||
|
||
```xml | ||
<StackPanel> | ||
<TextBlock>1</TextBlock> | ||
<TextBlock>2</TextBlock> | ||
</StackPanel> | ||
``` | ||
|
||
## TextBlock | ||
|
||
The `TextBlock` control allows extensive styling of its contained text. | ||
|
||
To take the example forward, add a `StackPanel` as follows (include the preexisting `Button` XAML): | ||
|
||
```xml | ||
<Window xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:vm="using:GetStartedApp.ViewModels" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="450" | ||
x:Class="GetStartedApp.Views.MainWindow" | ||
x:DataType="vm:MainWindowViewModel" | ||
Icon="/Assets/avalonia-logo.ico" | ||
Title="GetStartedApp"> | ||
|
||
<Design.DataContext> | ||
<!-- This only sets the DataContext for the previewer in an IDE, | ||
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) --> | ||
<vm:MainWindowViewModel/> | ||
</Design.DataContext> | ||
|
||
// highlight-start | ||
<StackPanel> | ||
<Border Margin="5" CornerRadius="10" Background="LightBlue"> | ||
<TextBlock Margin="5" | ||
FontSize="24" | ||
HorizontalAlignment="Center" | ||
Text="Temperature Converter"> | ||
</TextBlock> | ||
</Border> | ||
|
||
<Button HorizontalAlignment="Center">Calculate</Button> | ||
</StackPanel> | ||
// highlight-end | ||
</Window> | ||
|
||
``` | ||
|
||
<ThemedImage | ||
alt="Tempature StackPanel" | ||
className="center" | ||
sources={{ | ||
light: useBaseUrl('/img/get-started/test-drive/temperature-stackpanel-light.png'), | ||
dark: useBaseUrl('/img/get-started/test-drive/temperature-stackpanel-dark.png'), | ||
}} | ||
/> | ||
|
||
:::info | ||
You can explore the other layout controls in Avalonia using the reference [here](../../reference/controls/layout-controls.md). | ||
::: | ||
|
||
On the next page, you will add some inputs to the middle of the window. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.