![]() |
VOOZH | about |
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" />
<PackageVersion Include="MvvmDialogs.Avalonia.Ursa" Version="0.1.0" />Directory.Packages.props
<PackageReference Include="MvvmDialogs.Avalonia.Ursa" />Project file
paket add MvvmDialogs.Avalonia.Ursa --version 0.1.0
#r "nuget: MvvmDialogs.Avalonia.Ursa, 0.1.0"
#:package MvvmDialogs.Avalonia.Ursa@0.1.0
#addin nuget:?package=MvvmDialogs.Avalonia.Ursa&version=0.1.0Install as a Cake Addin
#tool nuget:?package=MvvmDialogs.Avalonia.Ursa&version=0.1.0Install as a Cake Tool
An implementation of HanumanInstitute.MvvmDialogs using Ursa.Avalonia as UI.
Use UrsaWindowDialogService if you want to show dialog as a Window, and UrsaOverlayDialogService as an Overlay Dialog.
Window dialog
Overlay dialog
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.
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 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0 | 286 | 2/23/2025 |