Better handle GoToPath, MessageBox customizations
This commit is contained in:
@@ -9,23 +9,28 @@ public partial class MessageBoxViewModel : IModalViewModel
|
||||
{
|
||||
private readonly Action<MessageBoxViewModel, MessageBoxResult> _handler;
|
||||
public string Text { get; }
|
||||
public bool ShowCancel { get; }
|
||||
public string OkText { get; }
|
||||
public string CancelText { get; }
|
||||
public string Name => "MessageBoxViewModel";
|
||||
|
||||
public MessageBoxViewModel(string text, Action<MessageBoxViewModel, MessageBoxResult> handler) : this()
|
||||
public MessageBoxViewModel(
|
||||
string text,
|
||||
Action<MessageBoxViewModel, MessageBoxResult> handler,
|
||||
bool showCancel = true,
|
||||
string? okText = null,
|
||||
string? cancelText = null) : this()
|
||||
{
|
||||
_handler = handler;
|
||||
Text = text;
|
||||
ShowCancel = showCancel;
|
||||
OkText = okText ?? "Yes";
|
||||
CancelText = cancelText ?? "No";
|
||||
}
|
||||
|
||||
[Command]
|
||||
public void Ok()
|
||||
{
|
||||
_handler.Invoke(this, MessageBoxResult.Ok);
|
||||
}
|
||||
public void Ok() => _handler.Invoke(this, MessageBoxResult.Ok);
|
||||
|
||||
[Command]
|
||||
public void Cancel()
|
||||
{
|
||||
_handler.Invoke(this, MessageBoxResult.Cancel);
|
||||
}
|
||||
public void Cancel() => _handler.Invoke(this, MessageBoxResult.Cancel);
|
||||
}
|
||||
@@ -119,14 +119,26 @@ public class DialogService : IDialogService
|
||||
});
|
||||
}
|
||||
|
||||
public Task<MessageBoxResult> ShowMessageBox(string text)
|
||||
public Task<MessageBoxResult> ShowMessageBox(
|
||||
string text,
|
||||
bool showCancel = true,
|
||||
string? okText = null,
|
||||
string? cancelText = null)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<MessageBoxResult>();
|
||||
_modalService.OpenModal(new MessageBoxViewModel(text, (vm, result) =>
|
||||
{
|
||||
_modalService.CloseModal(vm);
|
||||
taskCompletionSource.SetResult(result);
|
||||
}));
|
||||
_modalService.OpenModal(
|
||||
new MessageBoxViewModel(
|
||||
text,
|
||||
(vm, result) =>
|
||||
{
|
||||
_modalService.CloseModal(vm);
|
||||
taskCompletionSource.SetResult(result);
|
||||
},
|
||||
showCancel,
|
||||
okText,
|
||||
cancelText
|
||||
)
|
||||
);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
@@ -824,13 +824,14 @@
|
||||
Orientation="Horizontal">
|
||||
<Button
|
||||
Command="{Binding OkCommand}"
|
||||
Content="Yes"
|
||||
Content="{Binding OkText}"
|
||||
HorizontalContentAlignment="Center"
|
||||
Width="80" />
|
||||
<Button
|
||||
Command="{Binding CancelCommand}"
|
||||
Content="No"
|
||||
Content="{Binding CancelText}"
|
||||
HorizontalContentAlignment="Center"
|
||||
IsVisible="{Binding ShowCancel}"
|
||||
Margin="10,0,0,0"
|
||||
Width="80" />
|
||||
</StackPanel>
|
||||
|
||||
Reference in New Issue
Block a user