VOOZH about

URL: https://www.nuget.org/packages/MvvmDialogs.Avalonia.Ursa/

⇱ NuGet Gallery | MvvmDialogs.Avalonia.Ursa 0.1.0




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
 
 
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MvvmDialogs.Avalonia.Ursa" Version="0.1.0" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MvvmDialogs.Avalonia.Ursa" Version="0.1.0" />
 
Directory.Packages.props
<PackageReference Include="MvvmDialogs.Avalonia.Ursa" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MvvmDialogs.Avalonia.Ursa --version 0.1.0
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MvvmDialogs.Avalonia.Ursa, 0.1.0"
 
 
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MvvmDialogs.Avalonia.Ursa@0.1.0
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MvvmDialogs.Avalonia.Ursa&version=0.1.0
 
Install as a Cake Addin
#tool nuget:?package=MvvmDialogs.Avalonia.Ursa&version=0.1.0
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

MvvmDialogs.Avalonia.Ursa

👁 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 286 2/23/2025