This repository has been archived by the owner on Jun 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from kragt/textblock
Added basic TextBlock documentation
- Loading branch information
Showing
1 changed file
with
81 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
--- | ||
layout: control | ||
name: TextBlock | ||
group: controls | ||
--- | ||
[TextBlock]: https://avaloniaui.net/docs/controls/textblock | ||
[TextBlock API]: http://reference.avaloniaui.net/api/Avalonia.Controls/TextBlock/ | ||
[TextBlock.fs]: https://github.com/AvaloniaCommunity/Avalonia.FuncUI/blob/master/src/Avalonia.FuncUI.DSL/TextBlock.fs | ||
|
||
> *Note*: You can check the Avalonia docs for the [TextBlock] and [TextBlock API] if you need more information. | ||
> | ||
> For Avalonia.FuncUI's DSL properties you can check [TextBlock.fs] | ||
The textblock control allows you to present text within the application. | ||
|
||
## Usage | ||
|
||
### Basic usage | ||
```fsharp | ||
TextBlock.create [ | ||
TextBlock.text <text-for-box> | ||
] | ||
``` | ||
|
||
### Properties | ||
|
||
You will often want to specify how you want the text to look and TextBlock implements a number of properties to that end | ||
|
||
**Background** | ||
You can pass either a basic string or an IBrush instance for more control | ||
```fsharp | ||
TextBlock.create [ | ||
TextBlock.background "red" | ||
TextBlock.text "Critical malfunction!" | ||
] | ||
``` | ||
|
||
**Foreground** | ||
To set the text color, you can again pass either a basic string or an IBrush instance | ||
```fsharp | ||
TextBlock.create [ | ||
TextBlock.background "green" | ||
TextBlock.text "All systems operational." | ||
] | ||
``` | ||
|
||
**Font** The look of the font is specified by way of the fontFamily, fontSize, fontWeight and fontStyle properties | ||
```fsharp | ||
TextBlock.create [ | ||
TextBlock.fontFamily font // where font is an Avalonia.Media.FontFamily instance | ||
TextBlock.fontSize 24.0 | ||
TextBlock.fontWeight Avalonia.Media.FontWeight.Bold | ||
TextBlock.fontStyle Avalonia.Media.FontStyle.Italic | ||
TextBlock.text "Entrance restricted." | ||
] | ||
``` | ||
|
||
**Padding** TextBlock allows you to set the padding in several ways | ||
```fsharp | ||
TextBlock.create [ | ||
// using horizontal, vertical values | ||
TextBlock.padding (20.0, 10.0) | ||
// using left, top, right, bottom values | ||
TextBlock.padding (5.0, 10.0, 15.0, 20.0) | ||
// using an Avalonia.Thickness struct | ||
TextBlock.padding thickness | ||
TextBlock.text "It's nice with some space." | ||
] | ||
``` | ||
|
||
**Text formatting** Several properties are available to adjust how the content of the TextBlock is formatted | ||
```fsharp | ||
TextBlock.create [ | ||
TextBlock.lineHeight 16.0 | ||
TextBlock.maxLines 4 | ||
TextBlock.textWrapping Avalonia.Media.TextWrapping.Wrap | ||
TextBlock.textAlignment Avalonia.Media.TextAlignment.Center | ||
TextBlock.textTrimming Avalonia.Media.TextTrimming.WordEllipsis | ||
TextBlock.text "A longer paragraph could at times use some more formatting." | ||
] | ||
``` |