feat: fix memory leakage.
This commit is contained in:
@@ -17,6 +17,10 @@
|
||||
<Run Text="Result: "></Run>
|
||||
<Run Text="{Binding Result}"></Run>
|
||||
</TextBlock>
|
||||
<TextBlock>
|
||||
<Run Text="Date: "></Run>
|
||||
<Run Text="{Binding DialogViewModel.Date}"></Run>
|
||||
</TextBlock>
|
||||
<Button Command="{Binding ShowGlobalDialogCommand}">Show Dialog</Button>
|
||||
<Button Command="{Binding ShowLocalOverlayDialogCommand}">Show Local Overlay Dialog</Button>
|
||||
<Button Command="{Binding ShowGlobalOverlayDialogCommand}"> Show Global Overlay Dialog </Button>
|
||||
|
||||
@@ -23,6 +23,16 @@ public class DialogDemoViewModel: ObservableObject
|
||||
set => SetProperty(ref _result, value);
|
||||
}
|
||||
|
||||
private DateTime _date;
|
||||
|
||||
public DateTime Date
|
||||
{
|
||||
get => _date;
|
||||
set => SetProperty(ref _date, value);
|
||||
}
|
||||
|
||||
public DialogWithActionViewModel DialogViewModel { get; set; } = new DialogWithActionViewModel();
|
||||
|
||||
public DialogDemoViewModel()
|
||||
{
|
||||
ShowLocalOverlayDialogCommand = new AsyncRelayCommand(ShowLocalOverlayDialog);
|
||||
@@ -43,8 +53,10 @@ public class DialogDemoViewModel: ObservableObject
|
||||
|
||||
private async Task ShowLocalOverlayDialog()
|
||||
{
|
||||
var vm = new DialogWithActionViewModel();
|
||||
var result = await DialogBox.ShowOverlayAsync<DialogWithAction, DialogWithActionViewModel, bool>(
|
||||
new DialogWithActionViewModel(), "LocalHost");
|
||||
DialogViewModel, "LocalHost");
|
||||
Date = vm.Date;
|
||||
Result = result;
|
||||
}
|
||||
}
|
||||
@@ -20,10 +20,6 @@
|
||||
Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Content="{TemplateBinding Content}" />
|
||||
<StackPanel Grid.Row="2">
|
||||
<Button>OK</Button>
|
||||
<Button>Cancel</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
|
||||
@@ -10,8 +10,6 @@ public class DialogControl: ContentControl
|
||||
{
|
||||
public const string PART_CloseButton = "PART_CloseButton";
|
||||
|
||||
|
||||
|
||||
private Button? _closeButton;
|
||||
public event EventHandler<object?> OnClose;
|
||||
|
||||
@@ -38,17 +36,22 @@ public class DialogControl: ContentControl
|
||||
public Task<T> ShowAsync<T>()
|
||||
{
|
||||
var tcs = new TaskCompletionSource<T>();
|
||||
this.OnClose+= (sender, args) =>
|
||||
|
||||
void OnCloseHandler(object sender, object? args)
|
||||
{
|
||||
if (args is T result)
|
||||
{
|
||||
tcs.SetResult(result);
|
||||
OnClose-= OnCloseHandler;
|
||||
}
|
||||
else
|
||||
{
|
||||
tcs.SetResult(default);
|
||||
tcs.SetResult(default(T));
|
||||
OnClose-= OnCloseHandler;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
this.OnClose += OnCloseHandler;
|
||||
return tcs.Task;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user