feat: add prism extension.
This commit is contained in:
6
src/Ursa.PrismExtension/IUrsaDialogService.cs
Normal file
6
src/Ursa.PrismExtension/IUrsaDialogService.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Ursa.PrismExtension;
|
||||
|
||||
public interface IUrsaDialogService
|
||||
{
|
||||
|
||||
}
|
||||
6
src/Ursa.PrismExtension/IUrsaOverlayDialogService.cs
Normal file
6
src/Ursa.PrismExtension/IUrsaOverlayDialogService.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Ursa.PrismExtension;
|
||||
|
||||
public class IUrsaOverlayDialogService
|
||||
{
|
||||
|
||||
}
|
||||
18
src/Ursa.PrismExtension/Ursa.PrismExtension.csproj
Normal file
18
src/Ursa.PrismExtension/Ursa.PrismExtension.csproj
Normal file
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Ursa\Ursa.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Prism.Core" Version="8.1.97" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
26
src/Ursa.PrismExtension/UrsaDialogService.cs
Normal file
26
src/Ursa.PrismExtension/UrsaDialogService.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Avalonia.Controls;
|
||||
using Prism.Ioc;
|
||||
using Ursa.Controls;
|
||||
|
||||
namespace Ursa.PrismExtension;
|
||||
|
||||
public class UrsaDialogService(IContainerExtension container) : IUrsaDialogService
|
||||
{
|
||||
public void ShowCustom(string viewName, object? vm, Window? owner = null, DialogOptions? options = null)
|
||||
{
|
||||
var v = container.Resolve<Control>(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName);
|
||||
Dialog.ShowCustom(v, vm, owner, options);
|
||||
}
|
||||
|
||||
public Task<DialogResult> ShowModal(string viewName, object? vm, Window? owner = null, DialogOptions? options = null)
|
||||
{
|
||||
var v = container.Resolve<Control>(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName);
|
||||
return Dialog.ShowModal(v, vm, owner, options);
|
||||
}
|
||||
|
||||
public Task<TResult?> ShowCustomModal<TResult>(string viewName, object? vm, Window? owner = null, DialogOptions? options = null)
|
||||
{
|
||||
var v = container.Resolve<Control>(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName);
|
||||
return Dialog.ShowCustomModal<TResult>(v, vm, owner, options);
|
||||
}
|
||||
}
|
||||
20
src/Ursa.PrismExtension/UrsaDialogServiceExtension.cs
Normal file
20
src/Ursa.PrismExtension/UrsaDialogServiceExtension.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Avalonia.Controls;
|
||||
using Prism.Ioc;
|
||||
|
||||
namespace Ursa.PrismExtension;
|
||||
|
||||
public static class UrsaDialogServiceExtension
|
||||
{
|
||||
internal const string UrsaDialogViewPrefix = "URSA_DIALOG_VIEW_";
|
||||
|
||||
public static void RegisterDialogService(this IContainerRegistry containerRegistry)
|
||||
{
|
||||
containerRegistry.RegisterSingleton<IUrsaDialogService, UrsaDialogService>();
|
||||
containerRegistry.RegisterSingleton<IUrsaOverlayDialogService, UrsaOverlayDialogService>();
|
||||
}
|
||||
|
||||
public static void RegisterUrsaDialogView<T>(this IContainerRegistry containerRegistry, string name) where T : Control
|
||||
{
|
||||
containerRegistry.Register<Control, T>(UrsaDialogViewPrefix+name);
|
||||
}
|
||||
}
|
||||
32
src/Ursa.PrismExtension/UrsaOverlayDialogService.cs
Normal file
32
src/Ursa.PrismExtension/UrsaOverlayDialogService.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Avalonia.Controls;
|
||||
using Prism.Ioc;
|
||||
using Ursa.Controls;
|
||||
|
||||
namespace Ursa.PrismExtension;
|
||||
|
||||
public class UrsaOverlayDialogService(IContainerExtension container): IUrsaOverlayDialogService
|
||||
{
|
||||
public void Show(string viewName, object? vm, string? hostId = null, OverlayDialogOptions? options = null)
|
||||
{
|
||||
var v = container.Resolve<Control>(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName);
|
||||
OverlayDialog.Show(v, vm, hostId, options);
|
||||
}
|
||||
|
||||
public void ShowCustom(string viewName, object? vm, string? hostId = null, OverlayDialogOptions? options = null)
|
||||
{
|
||||
var v = container.Resolve<Control>(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName);
|
||||
OverlayDialog.ShowCustom(v, vm, hostId, options);
|
||||
}
|
||||
|
||||
public Task<DialogResult> ShowModal(string viewName, object? vm, string? hostId = null, OverlayDialogOptions? options = null)
|
||||
{
|
||||
var v = container.Resolve<Control>(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName);
|
||||
return OverlayDialog.ShowModal(v, vm, hostId, options);
|
||||
}
|
||||
|
||||
public Task<TResult?> ShowCustomModal<TResult>(string viewName, object? vm, string? hostId = null, OverlayDialogOptions? options = null)
|
||||
{
|
||||
var v = container.Resolve<Control>(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName);
|
||||
return OverlayDialog.ShowCustomModal<TResult>(v, vm, hostId, options);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user