feat: use another datatemplate collection.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Ursa.Common;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
@@ -86,7 +87,7 @@ public static class OverlayDialog
|
||||
var host = OverlayDialogManager.GetHost(hostId);
|
||||
if (host is null) return;
|
||||
var view = host.GetDataTemplate(vm)?.Build(vm);
|
||||
if (view is null) view = new ContentControl();
|
||||
if (view is null) view = new ContentControl() { Padding = new Thickness(24) };
|
||||
view.DataContext = vm;
|
||||
var t = new DialogControl()
|
||||
{
|
||||
@@ -146,11 +147,26 @@ public static class OverlayDialog
|
||||
|
||||
public static Task<TResult?> ShowCustomModal<TResult>(Control control, object? vm, string? hostId = null,
|
||||
OverlayDialogOptions? options = null)
|
||||
{
|
||||
var host = OverlayDialogManager.GetHost(hostId);
|
||||
if (host is null) return Task.FromResult(default(TResult));
|
||||
var t = new DialogControl()
|
||||
{
|
||||
Content = control,
|
||||
DataContext = vm,
|
||||
};
|
||||
ConfigureDialogControl(t, options);
|
||||
host?.AddModalDialog(t);
|
||||
return t.ShowAsync<TResult?>();
|
||||
}
|
||||
|
||||
public static Task<TResult?> ShowCustomModal<TResult>(object? vm, string? hostId = null,
|
||||
OverlayDialogOptions? options = null)
|
||||
{
|
||||
var host = OverlayDialogManager.GetHost(hostId);
|
||||
if (host is null) return Task.FromResult(default(TResult));
|
||||
var view = host.GetDataTemplate(vm)?.Build(vm);
|
||||
if (view is null) view = new ContentControl();
|
||||
if (view is null) view = new ContentControl() { Padding = new Thickness(24) };
|
||||
view.DataContext = vm;
|
||||
var t = new DialogControl()
|
||||
{
|
||||
|
||||
@@ -19,6 +19,9 @@ public class OverlayDialogHost : Canvas
|
||||
|
||||
private Point _lastPoint;
|
||||
|
||||
|
||||
public DataTemplates DialogDataTemplates { get; set; } = new DataTemplates();
|
||||
|
||||
public static readonly StyledProperty<IBrush?> OverlayMaskBrushProperty =
|
||||
AvaloniaProperty.Register<OverlayDialogHost, IBrush?>(
|
||||
nameof(OverlayMaskBrush));
|
||||
@@ -226,12 +229,18 @@ public class OverlayDialogHost : Canvas
|
||||
{
|
||||
if (o is null) return null;
|
||||
IDataTemplate? result = null;
|
||||
var templates = this.DataTemplates.ToList();
|
||||
var templates = this.DialogDataTemplates;
|
||||
result = templates.FirstOrDefault(a => a.Match(o));
|
||||
if (result != null) return result;
|
||||
var resources = this.Resources.Where(a => a.Value is IDataTemplate).Select(a => a.Value)
|
||||
.OfType<IDataTemplate>();
|
||||
result = resources.FirstOrDefault(a => a.Match(o));
|
||||
var keys = this.Resources.Keys;
|
||||
foreach (var key in keys)
|
||||
{
|
||||
if (Resources.TryGetValue(key, out var value) && value is IDataTemplate t)
|
||||
{
|
||||
result = t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user