avaloniaui / avalonia-docs Goto Github PK
View Code? Open in Web Editor NEWHome Page: https://docs.avaloniaui.net/docs/welcome
Home Page: https://docs.avaloniaui.net/docs/welcome
Coming from WPF's App.Current.Shutdown()
it is not immediately obvious what the analog is for Avalonia. After reading about Lifetimes, it makes sense why things are not as simple as WPF but still left me wondering "okay, so how do I quit the desktop app?"
Going the classic MVVM route I was essentially trying to map a "Quit" MenuItem
to shutdown the application and do any user prompting ceremony.
The first step was learning that the IClassicDesktopStyleApplicationLifetime
interface (try saying that 5 times fast) is where the expected Shutdown()
(or TryShutdown()
) method lives. But how would I access this from my MainWindowViewModel
?
The solution I came up with was to inject that lifetime into the VM and rework the startup code a bit:
App.axaml.cs:
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow { DataContext = new MainWindowViewModel(desktop) };
// Kinda gross, maybe pass (exitCode) => desktop.Shutdown(exitCode) instead?
}
base.OnFrameworkInitializationCompleted();
}
MainWindowViewModel.cs:
public sealed class MainWindowViewModel : ReactiveObject
{
// Maybe store an Action<int> requestQuit instead?
private readonly IClassicDesktopStyleApplicationLifetime _lifetime;
private string _windowTitle = App.AppName;
public string WindowTitle
{
get => _windowTitle;
set => this.RaiseAndSetIfChanged(ref _windowTitle, value);
}
public MainWindowViewModel(IClassicDesktopStyleApplicationLifetime lifetime)
{
_lifetime = lifetime;
}
public void OnQuitRequested() => _lifetime.Shutdown();
}
MainWindow.axaml:
...
<MenuItem Header="_Quit" HotKey="Ctrl+Q" Command="{ReflectionBinding OnQuitRequested}"/>
...
This works great and "feels" the most clean approach. I didn't love needing the entire lifetime interface stored by the VM, so maybe passing an Action<int> requestQuit
that calls lifetime.Shutdown(exitCode)
instead could be more de-coupled approach.
Anyways, it would be nice if something like this could be documented as it seems fairly elementary in the context of desktop applications.
E.g.
ItemsControl.ItemsPanel
using a FuncTemplate<T>
More and more people are interested in avalonia web programming, can you explain how avalonia uses signalR to communicate with the server? Thank you!
Original Issue: AvaloniaUI/Avalonia#11935
We need to update the Supported Platforms to include the following:
How to use
"I've had a quick look through the new documentation for version 11.0.0, but it doesn't seem to cover much on how to implement and use the INotifyPropertyChanged interface."
There is no info about Avalonia Notifications (except namespace section).
It's simple to use and i could add several Pages in Tutorials (?) section:
Stay-Up-To-Date > Whats-New
https://docs.avaloniaui.net/docs/controls/progressbar#customizing-the-progress-text
this page mentions you can customize the progress bar text. the version on the top says 0.10.x , but it seems this feature was added later and is not in a current 0.10.x release? is it planned for a 0.10.x release or will it only be in 11.x?
Hi, I will be glad to see separated Deployment section in documentation what will explain how to deploy finall app to final systems.
The avalonia web page https://docs.avaloniaui.net/docs/distribution-publishing/macos recommends nuget package Dotnet-Bundle for building MacOS app. However this no longer works and the developer says they can't support this tool and is seeking other contributers (see egramtel/dotnet-bundle#16 (comment))
Can you please update the avalonia docs to remove this recommendation or suggest a functional alternative?
Describe the bug
The documentation has entries for SplitButton and ToggleSplitButton, however in the XAML and in C# there's no Avalonia.Controls.SplitButton or ToggleSplitButton classes
To Reproduce
Expected behavior
The SplitButton should be restored, or the respective documentation removed
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Outside of Visual Studio or Rider environment, the docs just imply to
Alternatively you can install the Android command line tools from here
and give a link to AndroidDeveloper.
https://docs.avaloniaui.net/tutorials/developing-for-mobile/android/setting-up-your-developer-environment-for-android
Downloading the AndroidSDK that way does not setup Xamarin.Android.Tooling.targets
to have AndroidSdkDirectory and JavaSdkDirectory properties configured for the correct path.
As a result an error is thrown while compiling
This documentation update should cover users' questions from these issues: AvaloniaUI/Avalonia#6692 and AvaloniaUI/Avalonia#3100
Basics > User-Interface > File-Dialogs
People may want to define custom accents at runtime. Let's add docs about how to achieve this in v11.
Related: AvaloniaUI/Avalonia#11953
I've started to do a more detailed look at porting a UWP/WinUI app over to Avalonia and think a detailed guide would be useful (several apply to WPF as well). Below I'll collect the things I've found so far in the hopes of adding a dedicated page to the docs eventually.
XAML
xmlns="https://github.com/avaloniaui
x:CompileBindings="True"
where possible (it is supported in most cases now)ThemeResource
usages with DynamicResource
<ResourceDictionary.ThemeDictionaries>
Light/Dark/HighContrast dictionaries. Avalonia does not conceptually support this yet and will use a different pattern when this functionality is added. For now, resource dictionaries for dark/light should be manually loaded.UpdateSourceTrigger
usage which was common in WPF/WinUI TextBoxes. See AvaloniaUI/Avalonia#3754Grid
and StackPanel
Style
property usage. This usually requires switching to the Theme
property with a new ControlTheme
or use style classes.BorderBrush
, Background
and BorderThickness
property usage from Grid
. Place the Grid
inside a Border
which has these properties like what was done in WPF. UWP/WinUI did this to flatten the visual tree for performance but it never made a lot of sense as Grid was just layout and should have no visual style.ComboBox.SelectionChangedTrigger="Committed"
which isn't supported in AvaloniaDisplayMemberPath
, SelectedValue
and SelectedValuePath
: AvaloniaUI/Avalonia#4718. This requires some changes to view models to work-around and possibly switching types. More recently DisplayMemberBinding
was added to replace DisplayMemberPath
: AvaloniaUI/Avalonia#8922Visibility
to IsVisible
. This is one of the more involved changes and requires not only renames and property setter updates, but also converter and view model changes.Style
to ControlTheme
in the cases of default control template stylesStyle
to using selectors and classes when not changing control templatesSplitButton
, ToggleSplitButton
, DropDownButton
, ColorPicker
etc. out of the box.
ContentDialog
, etc.) It is best to use FluentAvalonia to add back most of the missing controls when porting from UWP/WinUIFontIcon
-> Fluent Avalonia's FontIcon
ListView
-> ListBox
DataTemplateSelector
pattern https://github.com/AvaloniaUI/Avalonia.Samples/tree/main/src/Avalonia.Samples/DataTemplates/IDataTemplateSampleAcrylicBrush
usage must be removed. Avalonia currently supports an experimental acrylic material but it is usable only on Border.Material
property so is conceptually different. Note that the entire window can still simulate acrylic/mica using different methodology TransparencyLevelHint="AcrylicBlur"
.x:Uid='key'
resource localization. For localized apps, this creates another very involved change. The recommended approach is to create a localization/translation markup extension and consume .resx files by the extension. See: AvaloniaUI/Avalonia#8741 (comment)IGrouping
cannot be used nor CollectionViewSource
or ListView.GroupStyle
. To work-around this custom ListBoxItems must be created with different data templates.Code-Behind
.ActualHeight
and .ActualWidth
must be changed to .Bounds.Height
and .Bounds.Width
UIElement
to object?
or IControl?
for content propertiesFrameworkElement
to Control
Brush
Background/BorderBrush to IBrush?
(Brush)Application.Current.Resources["key"];
generally doesn't work as it won't search the full resources (AvaloniaUI/Avalonia#6021). An extension method as described in the issue is generally the easiest fix but this still requires changing all usages in code.Other
Visibility
-> IsVisible
. This shows up everywhere.Note: I might complete a base version of this for my own public docs repository. We'll see. Just collecting things here for now.
I am new to Avalonia, but quite experienced with WPF and develop using Rider on macOS.
While developing my UI, I wanted to support the native menu bar at the top of the screen. Going through the documentation, I could not find anything about this. Looking in the Controls section I found NativeMenu but it is not clear how it works.
Then I found an older Github issue that mentions NativeMenuBar
but that's not in the docs. Ultimately, I searched the entire repo for this and found an integration test example that uses it in XAML.
Using that I got it to work, but it shows Avalonia Application
as in the macOS menu bar instead of my window title. Still not sure how/where to change that.
It would be really nice to update the docs with how to use NativeMenuBar
and NativeMenu
for cross-platform UIs.
From https://github.com/AvaloniaUI/Documentation/issues/399
Must be added before 11.0 release:
Nice to have
Won't be added:
Something from the 0.10 that really should be documented. Note, there are a lot more missing documentation pages, but I want to mention here major Avalonia features that get lots of questions about.:
Issues in old repro marked with "Content request":
It's easy to misunderstand what is Avalonia's role on mobile and look for various packaging related documentation pages.
When in fact Avalonia does not do any packaging, so all the signing, icon related, dependencies questions should be redirected to the official Microsoft tooling.
For example, "How to add icon to Avalonia iOS app" should redirect users to the https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/images-icons/app-icons?tabs=macos page ("How to add icon to .NET iOS app").
Short explanation of how exactly Avalonia works on top of mobile/wasm .NET runtime would be helpful as well.
It will be nice to have documentation of control lifecycle, explaining the order of methods executed, when elements are attached to trees, or templates are applied to control.
Describe the bug
It does not build. I installed nuget "Avalonia.Themes.Fluent"
<FluentTheme Mode="Light"/>
Expected behavior
Very simple app, should be running. If I remove the xml line from App.axaml, the app will run having no background window or anything.
Desktop (please complete the following information):
https://docs.avaloniaui.net/docs/next/tutorials/music-store-app/creating-a-modern-looking-window
Need to update information about ThemeVariant. There’s old version with Mode=“”. Should be RequestedThemeVariant
Add docs after AvaloniaUI/Avalonia#7838 is merged
Originally posted by nielsbosma June 7, 2022
Would be great with a list of things to consider when optimizing performance in Avalonia.
I assume some of these also apply to Avalonia?:
https://dzone.com/articles/15-wpf-performance-tips-for-2019
http://www.wpftutorial.net/10performancetips.html
Sample and docs
I see often questeions about how to use the OpenGL control. So I think we need to add docs about this control.
The page on the <Grid>
control (source) makes no mention of the SharedSizeGroup
property on RowDefinition
and ColumnDefinition
. The related Grid.IsSharedSizeScope
is missing as well.
This page should be edited to include a sample <Grid>
based <ItemsRepeater>
example. For my case, it's to have a bit more control over the layout and look of the <DataGrid>
control. So I use something like this:
public class TestModel
{
public string ColumnA { get; }
public string ColumnB { get; }
public string ColumnC { get; }
public string ColumnD { get; }
public TestModel(string a, string b, string c, string d)
{
ColumnA = a;
ColumnB = b;
ColumnC = c;
ColumnD = d;
}
}
<StackPanel
Grid.IsSharedSizeScope="True"
Orientation="Vertical"
Spacing="6">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="a" />
<ColumnDefinition Width="Auto" SharedSizeGroup="b" />
<ColumnDefinition Width="Auto" SharedSizeGroup="c" />
<ColumnDefinition Width="*" SharedSizeGroup="d" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" FontSize="14" FontWeight="Bold" Margin="6" Text="Column A" />
<TextBlock Grid.Column="1" FontSize="14" FontWeight="Bold" Margin="6" Text="Column B" />
<TextBlock Grid.Column="2" FontSize="14" FontWeight="Bold" Margin="6" Text="Column C" />
<TextBlock Grid.Column="3" FontSize="14" FontWeight="Bold" Margin="6" Text="Column D" />
</Grid>
<ItemsRepeater Items="{CompiledBinding TestEntries}">
<ItemsRepeater.ItemTemplate>
<DataTemplate DataType="models:TestModel">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="a" />
<ColumnDefinition Width="Auto" SharedSizeGroup="b" />
<ColumnDefinition Width="Auto" SharedSizeGroup="c" />
<ColumnDefinition Width="*" SharedSizeGroup="d" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Margin="6" Text="{CompiledBinding ColumnA}" />
<TextBlock Grid.Column="1" Margin="6" Text="{CompiledBinding ColumnB}" />
<TextBlock Grid.Column="2" Margin="6" Text="{CompiledBinding ColumnC}" />
<TextBlock Grid.Column="3" Margin="6" Text="{CompiledBinding ColumnD}" />
</Grid>
</DataTemplate>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater>
</StackPanel>
This example shows how one can share column widths between different <Grid>
controls[a], but the wrapping <StackPanel>
and <Grid>
could possibly be removed for a simpler example.
Should also mention that the names don't matter, as long as they're unique for each unique column width desired.
[a]: Yes, the <ItemsRepeater>
generates multiple <Grid>
controls (one for each row), but it's not entirely clear to beginners that that's happening. This example makes the sharing of widths more clear. Without it, one might be confused why they'd need the SharedGroupSize
property.
Missing migratotion custom ItemsControl AvaloniaUI/Avalonia#9677
Certain important things are documented in the Wiki and not in the Avalonia documentation. So one has to dig really deep to get into that separate documentation.
I think this page should be in the main documentation.
Configuring X11 per monitor DPI
Sample project:
Archive.zip
Originally posted by kyuranger June 29, 2023
Recently I am working on try run my program on Raspberry Pi with Raspbian Lite.
I followed this tutorial:
https://docs.avaloniaui.net/docs/next/guides/platforms/rpi/running-on-raspbian-lite-via-drm
I did all the steps one by one.
Whereas, in step 2.3 Prepare Program.cs , it said I should modify the code like this:
public static int Main(string[] args)
{
var builder = BuildAvaloniaApp();
if (args.Contains("--drm"))
{
SilenceConsole();
return builder.StartLinuxDrm(args);
}
return builder.StartWithClassicDesktopLifetime(args);
}
I did what is said and Visual Studio reports an error:
The call is ambiguous between the following methods or properties: 'LinuxFramebufferPlatformExtensions.StartLinuxDrm(AppBuilder, string[], string?, double, IInputBackend?)' and 'LinuxFramebufferPlatformExtensions.StartLinuxDrm(AppBuilder, string[], string?, bool, DrmOutputOptions?, IInputBackend?)'
My project was created by 11 Preview 5 a long time ago and continuously upgraded to 11 RC1. All the nuget package is on 11 RC1 also. Currently my program runs well on windows. What's wrong with it?
The current documentation of the RadioButton
is very bare bones and does not explain how to use it/has no examples/does not show how to property bind to the value.
It would be really useful to have some clear examples that focus on the "Provider" Architectural Pattern with dependency injection that focuses on native APIs; RFID support might be a really good candidate.
Windows, Linux, MacOS and Android should support it nicely but iOS might not.
That could be a great opportunity on how to handle platforms that do not support a specific functionality.
The Custom Flyout sample has a few issues.
CreatePresenter
no longer exists on FlyoutBase
(it is part of PopupFlyoutBase
)[!Image.SourceProperty] = this[!ImageProperty]
: this line doesn't compile. Image
is both a class property and type. The compiler picks the property instead of the Image
type.following PR AvaloniaUI/Documentation#368 we should add also some docs about how to enable validation for custom controls.
There's basically no documentation about mouse and touch events, and there's a decent bit of nuance that's not necessarily obvious.
One big example is capture. When is capture gained? When is it lost? What happens if the control which has captured the pointer has is moved/deactived/hidden while the mousebutton is still down? I don't want to deal with missing button release events.
Another use case is finding out what control is beneath the pointer when the button is released. In my case, I want a Visual Studio like docking control, so I'm handing over a control to a different part of the visual and logical trees on mouse release, provided the mouse is over a valid target.
The problem is that DragDrop is severely inadequate for this sort of use. I can of course serialize a reference into a string and back again, and use reflection to validate types, but this is a horrible kludge, and I don't particularly want my app leaking object references or other odd side effects if the user happens to drag something meant for internal use off to another program or over a textbox or something. However, to my knowledge, there just isn't a better way to do it.
from our chat:
Tim, [19.08.2022 11:43]
the question is, is Item the only supported syntax?
Tim, [19.08.2022 11:43]
or is Item[theKey] also working?
Tim, [19.08.2022 11:44]
And is MyOtherIndexedProperty.Item working?
So I can start to add Chinese docs.
There is a page (3 pages) in the documentation about opening dialogs here. It's a very complicated approach.
I just published HanumanInstitute.MvvmDialogs which makes this kind of operation super simple. I think the documentation should be updated to include this much simpler approach. With at least a link; the library's usage is well-documented already.
"And I think the navigation is mentioned only in Samples & Tutorials and it looks like the navigation remained the same as in the previous version."
I think it might be a good idea to change the current 'Deployment / Publishing' section to 'Platforms', which then sub-sections for each supported platform. We can then have the deployment docs and other platform-specific info within these sub-sections.
I imagine a structure something like:
Basics > User-Interface > Adding-Interactivity
List here the places where the docs are out of date:
It is necessary to add information about UniformGrid to the page https://docs.avaloniaui.net/docs/layout/panels-overview
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.