add restart with windows and autorestart

This commit is contained in:
thuannd88
2024-09-06 23:23:19 +07:00
parent bcfef9d82d
commit 84d9f15ab7
10 changed files with 306 additions and 24 deletions
+24 -16
View File
@@ -47,26 +47,34 @@ namespace VirtualKeyboard.Wpf
public static Task<string> OpenAsync(string initialValue = "")
{
if (_windowHost != null) throw new InvalidOperationException();
_tcs = new TaskCompletionSource<string>();
_windowHost = (Window)Activator.CreateInstance(_hostType);
_windowHost.DataContext = new VirtualKeyboardViewModel(initialValue);
((ContentControl)_windowHost.FindName(_keyboardValueName)).Content = new KeyboardValueView();
((ContentControl)_windowHost.FindName(_keyboardName)).Content = new VirtualKeyboardView();
void handler(object s, CancelEventArgs a)
try
{
var result = GetResult();
((Window)s).Closing -= handler;
_windowHost = null;
_tcs?.SetResult(result);
_tcs = null;
if (_windowHost != null) throw new InvalidOperationException();
_windowHost = (Window)Activator.CreateInstance(_hostType);
_windowHost.DataContext = new VirtualKeyboardViewModel(initialValue);
((ContentControl)_windowHost.FindName(_keyboardValueName)).Content = new KeyboardValueView();
((ContentControl)_windowHost.FindName(_keyboardName)).Content = new VirtualKeyboardView();
void handler(object s, CancelEventArgs a)
{
var result = GetResult();
((Window)s).Closing -= handler;
_windowHost = null;
_tcs?.SetResult(result);
_tcs = null;
}
_windowHost.Closing += handler;
_windowHost.Owner = Application.Current.MainWindow;
_windowHost.Show();
}
catch (Exception ex) {
_windowHost.Closing += handler;
_windowHost.Owner = Application.Current.MainWindow;
_windowHost.Show();
}
return _tcs.Task;
}