feat: use another datatemplate collection.
This commit is contained in:
@@ -71,7 +71,13 @@
|
|||||||
</TabControl>
|
</TabControl>
|
||||||
<Grid Grid.Column="1">
|
<Grid Grid.Column="1">
|
||||||
<Border ClipToBounds="True" CornerRadius="20" BorderThickness="1" BorderBrush="{DynamicResource SemiGrey1}">
|
<Border ClipToBounds="True" CornerRadius="20" BorderThickness="1" BorderBrush="{DynamicResource SemiGrey1}">
|
||||||
<u:OverlayDialogHost HostId="LocalHost" />
|
<u:OverlayDialogHost HostId="LocalHost">
|
||||||
|
<u:OverlayDialogHost.DialogDataTemplates>
|
||||||
|
<DataTemplate DataType="x:String">
|
||||||
|
<TextBlock Text="{Binding Path=.}" Foreground="Red" Margin="24 24 48 24"></TextBlock>
|
||||||
|
</DataTemplate>
|
||||||
|
</u:OverlayDialogHost.DialogDataTemplates>
|
||||||
|
</u:OverlayDialogHost>
|
||||||
</Border>
|
</Border>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Avalonia.Controls;
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
using Ursa.Common;
|
using Ursa.Common;
|
||||||
|
|
||||||
namespace Ursa.Controls;
|
namespace Ursa.Controls;
|
||||||
@@ -86,7 +87,7 @@ public static class OverlayDialog
|
|||||||
var host = OverlayDialogManager.GetHost(hostId);
|
var host = OverlayDialogManager.GetHost(hostId);
|
||||||
if (host is null) return;
|
if (host is null) return;
|
||||||
var view = host.GetDataTemplate(vm)?.Build(vm);
|
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;
|
view.DataContext = vm;
|
||||||
var t = new DialogControl()
|
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,
|
public static Task<TResult?> ShowCustomModal<TResult>(Control control, object? vm, string? hostId = null,
|
||||||
OverlayDialogOptions? options = 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);
|
var host = OverlayDialogManager.GetHost(hostId);
|
||||||
if (host is null) return Task.FromResult(default(TResult));
|
if (host is null) return Task.FromResult(default(TResult));
|
||||||
var view = host.GetDataTemplate(vm)?.Build(vm);
|
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;
|
view.DataContext = vm;
|
||||||
var t = new DialogControl()
|
var t = new DialogControl()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ public class OverlayDialogHost : Canvas
|
|||||||
|
|
||||||
private Point _lastPoint;
|
private Point _lastPoint;
|
||||||
|
|
||||||
|
|
||||||
|
public DataTemplates DialogDataTemplates { get; set; } = new DataTemplates();
|
||||||
|
|
||||||
public static readonly StyledProperty<IBrush?> OverlayMaskBrushProperty =
|
public static readonly StyledProperty<IBrush?> OverlayMaskBrushProperty =
|
||||||
AvaloniaProperty.Register<OverlayDialogHost, IBrush?>(
|
AvaloniaProperty.Register<OverlayDialogHost, IBrush?>(
|
||||||
nameof(OverlayMaskBrush));
|
nameof(OverlayMaskBrush));
|
||||||
@@ -226,12 +229,18 @@ public class OverlayDialogHost : Canvas
|
|||||||
{
|
{
|
||||||
if (o is null) return null;
|
if (o is null) return null;
|
||||||
IDataTemplate? result = null;
|
IDataTemplate? result = null;
|
||||||
var templates = this.DataTemplates.ToList();
|
var templates = this.DialogDataTemplates;
|
||||||
result = templates.FirstOrDefault(a => a.Match(o));
|
result = templates.FirstOrDefault(a => a.Match(o));
|
||||||
if (result != null) return result;
|
if (result != null) return result;
|
||||||
var resources = this.Resources.Where(a => a.Value is IDataTemplate).Select(a => a.Value)
|
var keys = this.Resources.Keys;
|
||||||
.OfType<IDataTemplate>();
|
foreach (var key in keys)
|
||||||
result = resources.FirstOrDefault(a => a.Match(o));
|
{
|
||||||
|
if (Resources.TryGetValue(key, out var value) && value is IDataTemplate t)
|
||||||
|
{
|
||||||
|
result = t;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user