feat: set result.
This commit is contained in:
@@ -42,13 +42,13 @@ public class DialogDemoViewModel: ObservableObject
|
|||||||
|
|
||||||
private async Task ShowGlobalDialog()
|
private async Task ShowGlobalDialog()
|
||||||
{
|
{
|
||||||
var result = await DialogBox.ShowAsync<DialogWithAction, DialogWithActionViewModel, bool>(new DialogWithActionViewModel());
|
var result = await DialogBox.ShowAsync<DialogWithAction, DialogWithActionViewModel, bool>(DialogViewModel);
|
||||||
Result = result;
|
Result = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ShowGlobalOverlayDialog()
|
private async Task ShowGlobalOverlayDialog()
|
||||||
{
|
{
|
||||||
await DialogBox.ShowOverlayAsync<DialogWithAction, DialogWithActionViewModel, bool>(new DialogWithActionViewModel(), "GlobalHost");
|
Result = await DialogBox.ShowOverlayAsync<DialogWithAction, DialogWithActionViewModel, bool>(DialogViewModel, "GlobalHost");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ShowLocalOverlayDialog()
|
private async Task ShowLocalOverlayDialog()
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Controls.Metadata;
|
using Avalonia.Controls.Metadata;
|
||||||
using Avalonia.Controls.Primitives;
|
using Avalonia.Controls.Primitives;
|
||||||
@@ -11,7 +12,26 @@ public class DialogControl: ContentControl
|
|||||||
public const string PART_CloseButton = "PART_CloseButton";
|
public const string PART_CloseButton = "PART_CloseButton";
|
||||||
|
|
||||||
private Button? _closeButton;
|
private Button? _closeButton;
|
||||||
public event EventHandler<object?> OnClose;
|
public event EventHandler<object?>? OnClose;
|
||||||
|
|
||||||
|
static DialogControl()
|
||||||
|
{
|
||||||
|
DataContextProperty.Changed.AddClassHandler<DialogControl, object?>((o, e) => o.OnDataContextChange(e));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDataContextChange(AvaloniaPropertyChangedEventArgs<object?> args)
|
||||||
|
{
|
||||||
|
if (args.OldValue.Value is IDialogContext oldContext)
|
||||||
|
{
|
||||||
|
oldContext.Closed-= Close;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.NewValue.Value is IDialogContext newContext)
|
||||||
|
{
|
||||||
|
newContext.Closed += Close;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||||
{
|
{
|
||||||
@@ -25,11 +45,6 @@ public class DialogControl: ContentControl
|
|||||||
{
|
{
|
||||||
_closeButton.Click += Close;
|
_closeButton.Click += Close;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.DataContext is IDialogContext context)
|
|
||||||
{
|
|
||||||
context.Closed += Close;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user