MvvmDialogs.Avalonia.Ursa
0.1.0
dotnet add package MvvmDialogs.Avalonia.Ursa --version 0.1.0
NuGet\Install-Package MvvmDialogs.Avalonia.Ursa -Version 0.1.0
<PackageReference Include="MvvmDialogs.Avalonia.Ursa" Version="0.1.0" />
paket add MvvmDialogs.Avalonia.Ursa --version 0.1.0
#r "nuget: MvvmDialogs.Avalonia.Ursa, 0.1.0"
// Install MvvmDialogs.Avalonia.Ursa as a Cake Addin #addin nuget:?package=MvvmDialogs.Avalonia.Ursa&version=0.1.0 // Install MvvmDialogs.Avalonia.Ursa as a Cake Tool #tool nuget:?package=MvvmDialogs.Avalonia.Ursa&version=0.1.0
MvvmDialogs.Avalonia.Ursa
An implementation of HanumanInstitute.MvvmDialogs using Ursa.Avalonia as UI.
Usage
Use UrsaWindowDialogService
if you want to show dialog as a Window, and UrsaOverlayDialogService
as an Overlay Dialog.
Screenshots
Window dialog
Overlay dialog
DialogContext
A problem of using MVVM Dialog is how to identify the owner Window, especially when your APP has multiple windows.
DialogContext
can be used to find owner Window. Implement IDialogContextOwner
interface in your ViewModel class, set DialogContext.ToplevelHashCode
as the HashCode of the window you want to show dialog in, and set this
as owner ViewModel when show dialog. The manager would automatically find the right window.
DialogContext.HostId
is used to find OverlayDialogHost
when using UrsaOverlayDialogService
. This is required only when you are using a OverlayDialogHost
in you control; if you use UrsaWindow
or UrsaView
, just set the ToplevelHashCode as the owner window's hashcode, Ursa can find the right window and OverlayDialogHost to show dialog in.
Best Practices
When you are using IoC container, the best way to use DialogContext
is implementing a DialogContextProvider:
public class DialogContextProvider
{
public DialogContext DialogContext { get; set; } = new DialogContext(0, null);
}
Register the DialogContextProvider as scoped service. In ViewLocator, set the DialogContext when create a new window:
public class ViewLocator : StrongViewLocator
{
private readonly IDialogContextProvider _dialogContextProvider;
public ViewLocator(IDialogContextProvider dialogContextProvider)
{
_dialogContextProvider = dialogContextProvider;
RegisterViews();
}
public override object Create(object viewModel)
{
var control = base.Create(viewModel);
if (control is Window window)
{
_dialogContextProvider.DialogContext = new DialogContext(window.GetHashCode(), null);
}
return control;
}
public void RegisterViews()
{
....
}
}
And create a new scope when you start a new window:
serviceCollection.AddScoped<IDialogContextProvider, DialogContextProvider>();
....
public class YourViewModel : ViewModelBase, IDialogContextOwner
{
private readonly IServiceProvider _serviceProvider;
private readonly IDialogService _dialogService;
private readonly IDialogContextProvider _dialogContextProvider;
//Constructor is omited
public DialogContext? DialogContext
{
get => _dialogContextProvider.DialogContext;
set
{
if(value!=null)
_dialogContextProvider.DialogContext = value;
}
}
public async Task SomeCommand()
{
var scope = _serviceProvider.CreateScope();
var vm = scope.ServiceProvider.GetRequiredService<YourDialogViewModel>();
await _windowDialogService.ShowDialogAsync(this, vm);
}
}
Both window and overlay dialog will be shown in the right window.
To find a full sample, see the MvvmDialogs.Avalonia.Ursa.Demo
project.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net8.0
- HanumanInstitute.MvvmDialogs (>= 2.1.0)
- HanumanInstitute.MvvmDialogs.Avalonia (>= 2.1.0)
- Irihi.Avalonia.Shared (>= 0.2.3)
- Irihi.Ursa (>= 1.6.0)
- Irihi.Ursa.Themes.Semi (>= 1.6.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.1.0 | 82 | 2/23/2025 |