DialogHost.Avalonia
0.7.0-preview8
See the version list below for details.
dotnet add package DialogHost.Avalonia --version 0.7.0-preview8
NuGet\Install-Package DialogHost.Avalonia -Version 0.7.0-preview8
<PackageReference Include="DialogHost.Avalonia" Version="0.7.0-preview8" />
paket add DialogHost.Avalonia --version 0.7.0-preview8
#r "nuget: DialogHost.Avalonia, 0.7.0-preview8"
// Install DialogHost.Avalonia as a Cake Addin #addin nuget:?package=DialogHost.Avalonia&version=0.7.0-preview8&prerelease // Install DialogHost.Avalonia as a Cake Tool #tool nuget:?package=DialogHost.Avalonia&version=0.7.0-preview8&prerelease
DialogHost.Avalonia
Avalonia DialogHost control that provides a simple way to display a dialog with information or prompt the user when information is required.
Dialogs in Avalonia have always been somewhat tricky. This implementation is designed to:
- Provide correct styling
- Allow any dialog to be constructed
- Compatible with code-behind
- Compatible with MVVM
- Compatible with pure XAML
- Work in applications with multiple windows
Dialogs are asynchronous so at some point you will have to deal with that in your code.
Getting started
Install
DialogHost.Avalonia
nuget packagedotnet add package DialogHost.Avalonia
Add DialogHostStyles element to your app styles in
App.axaml
. See the example ofApp.axaml
:<Application ... xmlns:dialogHostAvalonia="clr-namespace:DialogHostAvalonia;assembly=DialogHost.Avalonia" ...> ... <Application.Styles> ... <dialogHostAvalonia:DialogHostStyles /> </Application.Styles> ... </Application>
Start using control
Using
The cornerstone of dialogs the DialogHost control. It’s a content control, meaning the underlying content over which the popup dialog will be displayed can be targeted; to a specific area of your app, or the entire Window content.
<Window ...
xmlns:dialogHost="clr-namespace:DialogHost;assembly=DialogHost.Avalonia"
...
Title="DialogHost.Demo">
<dialogHost:DialogHost CloseOnClickAway="True">
<dialogHost:DialogHost.DialogContent>
</dialogHost:DialogHost.DialogContent>
</dialogHost:DialogHost>
</Window>
When the dialog is open, the underlying content will be dimmed and disabled.
DialogHost.DialogContent
(associated with DialogHost.DialogContentTemplate
) is your typical XAML content object
property for setting the content of your dialog. You can infer from this that you can use MVVM to bind content, but
there are multiple ways of populating the content, showing the dialog, closing the dialog, and processing responses.
Alternative way
- HanumanInstitute.MvvmDialogs allows the use of MVVM design in a simplified way, with DialogHost support. If you opt for that syntax, you do not need most of the documentation below, and the DialogHost container is injected to window automatically at runtime.
Open Dialog Strategies
OpenDialogCommand
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=materialDesign:DialogHost}, Path=OpenDialogCommand}"
ICommand, typically used on buttons, where DialogContent can be set via CommandParameter.
IsOpen
<dialogHost:DialogHost IsOpen="True" />
Dependency property, to be triggered from XAML, set from code-behind or via a binding. Content must be set in DialogHost.DialogContent.
DialogHost.Show
DialogHost.Show(viewOrModel);
Async/await based static API which can be used purely in code (for example from in a view model). Content can be passed
directly to the dialog. Note that if you have multiple windows and multiple DialogHost instances you can set
the DialogHost.Identifier
property, and provide the identifier to the .Show(...) method to help find the required
DialogHost.
Close Dialog Strategies
CloseDialogCommand
You can bind to the DialogHost's OpenDialogCommand:
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=materialDesign:DialogHost}, Path=CloseDialogCommand}"
ICommand, typically used on buttons inside the dialog, where the command parameter will be passed along to the dialog response.
IsOpen
<dialogHost:DialogHost IsOpen="False" />
Dependency property, to be triggered from XAML, set from code-behind or via a binding.
DialogSession.Close
Via any of the methods for handling the opened event, you can get hold of the dialog session. This can be used to close a dialog via code:
var result = await DialogHost.Show(myContent, delegate(object sender, DialogOpenedEventArgs args)
{
args.Session.Close(false);
});
or getting DialogSession
DialogHost.GetDialogSession("DialogHost.Identifier here")?.Close(false);
Handle Closing Event Strategies
The DialogClosingEventHandler delegate is key. It provides the parameter provided to DialogHost.CloseDialogCommand, and allows the pending close to be cancelled.
The following mechanisms allow handling of this event, via code-behind, MVVM practices, or just from the code API:
DialogHost.DialogClosing
<dialogHost:DialogHost DialogClosing="DialogHost_OnDialogClosing" />
Bubbling RoutedEvent, which could be used in code-behind.
DialogClosing.DialogClosingCallback
<dialogHost:DialogHost DialogClosingCallback="{Binding DialogClosingHandler}" />
Standard dependency property which enables the DialogClosingEventHandler implementation to be bound, typically from a view model.
DialogHost.Show
var result = await DialogHost.Show(viewOrModel, ClosingEventHandler);
The async response from this method returns the parameter provided when DialogHost.CloseDialogCommand
was executed. As
part of the Show()
signature a DialogClosingEventHandler
delegate can be provided to intercept the on-closing event,
just prior to the close.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Avalonia (>= 11.0.0-preview6)
- System.Reactive (>= 5.0.0)
NuGet packages (8)
Showing the top 5 NuGet packages that depend on DialogHost.Avalonia:
Package | Downloads |
---|---|
MessageBox.Avalonia
Messagebox for AvaloniaUI |
|
Spice86
Reverse engineer and rewrite real mode DOS programs |
|
Neumorphism.Avalonia
Easy to use and customizable Neumorphism Design implementation for Avalonia UI framework. |
|
HanumanInstitute.MvvmDialogs.Avalonia.DialogHost
Library simplifying the concept of opening dialogs from a view model when using MVVM in WPF |
|
AvaloniaDialogs
A library wrapping DialogHost.Avalonia, providing a more convenient API and built-in common dialogs such as a Yes/No popup and a snackbar. |
GitHub repositories (13)
Showing the top 5 popular GitHub repositories that depend on DialogHost.Avalonia:
Repository | Stars |
---|---|
2dust/v2rayN
A GUI client for Windows and Linux, support Xray core and sing-box-core and others
|
|
Tyrrrz/YoutubeDownloader
Downloads videos and playlists from YouTube
|
|
Tyrrrz/DiscordChatExporter
Exports Discord chat logs to a file
|
|
roslynpad/roslynpad
A cross-platform C# editor based on Roslyn and AvalonEdit
|
|
Tyrrrz/LightBulb
Reduces eye strain by adjusting screen gamma based on the current time
|
Version | Downloads | Last updated |
---|---|---|
0.9.0-preview3 | 304 | 11/17/2024 |
0.9.0-preview2 | 138 | 11/9/2024 |
0.9.0-preview1 | 475 | 9/30/2024 |
0.8.1 | 49,814 | 8/21/2024 |
0.8.0 | 299 | 8/20/2024 |
0.8.0-avalonia11dot1-3 | 1,928 | 6/22/2024 |
0.8.0-avalonia11dot1-2 | 105 | 6/21/2024 |
0.8.0-avalonia11dot1-1.2 | 153 | 6/15/2024 |
0.8.0-avalonia11dot1-1 | 716 | 4/11/2024 |
0.7.9 | 8,039 | 6/22/2024 |
0.7.8 | 304 | 6/19/2024 |
0.7.7 | 184,038 | 9/11/2023 |
0.7.6 | 47,883 | 8/5/2023 |
0.7.5 | 29,887 | 7/1/2023 |
0.7.4 | 2,158 | 6/1/2023 |
0.7.3 | 830 | 4/29/2023 |
0.7.2 | 560 | 4/21/2023 |
0.7.1 | 471 | 4/19/2023 |
0.7.0 | 650 | 3/29/2023 |
0.7.0-preview9 | 361 | 3/27/2023 |
0.7.0-preview8 | 507 | 3/25/2023 |
0.7.0-preview7 | 391 | 3/23/2023 |
0.7.0-preview6 | 441 | 3/20/2023 |
0.7.0-preview5 | 389 | 3/11/2023 |
0.7.0-preview4 | 689 | 2/5/2023 |
0.7.0-preview3 | 790 | 1/6/2023 |
0.7.0-preview2 | 489 | 12/12/2022 |
0.7.0-preview1 | 428 | 11/21/2022 |
0.6.0 | 3,684 | 11/6/2022 |
0.6.0-avalonia10 | 651 | 11/6/2022 |
0.5.1 | 823 | 9/4/2022 |
0.5.0 | 6,939 | 7/2/2022 |
0.4.0 | 22,825 | 2/24/2022 |
0.3.1 | 15,939 | 9/10/2021 |
0.3.0 | 605 | 7/17/2021 |
0.2.2 | 582 | 7/15/2021 |
0.2.1 | 540 | 7/14/2021 |
0.2.0 | 632 | 6/3/2021 |
0.1.1 | 604 | 5/5/2021 |
0.1.0 | 773 | 5/4/2021 |
- Add compability with Avalonia 11 preview6
- Add IDialogPopupPositioner to allow manipilation of Dialog placement
- Fix AlignmentDialogPopupPositioner margin doesn't work when align top left corner #17
- Add DialogHost.Show overloads accepting a DialogHost instance (instead of string identifier) #18 by profix898
- Fix "The control already has a visual parent" #22
- Fix "Invalid priority $Unset Arg_ParamName_Name" #25
- Migrate all styles to ControlThemes
- Add DialogHostStyles class for adding styles more convenient way
- Expose BorderBrushProperty and BorderThicknessProperty properties #26