Switched to Avalonia
This commit is contained in:
77
ParentAvalonia/MainWindow.axaml.cs
Normal file
77
ParentAvalonia/MainWindow.axaml.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
|
||||
namespace ParentAvalonia;
|
||||
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private readonly MainViewModel _vm;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
_vm = new MainViewModel();
|
||||
DataContext = _vm;
|
||||
|
||||
Closed += async (_, __) =>
|
||||
{
|
||||
try { await _vm.DisposeAsync(); } catch { }
|
||||
};
|
||||
}
|
||||
|
||||
private async void StartChildren_Click(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
try { await _vm.StartChildrenAsync(count: 3); }
|
||||
catch (Exception ex) { await MessageBoxAsync(ex.Message); }
|
||||
}
|
||||
|
||||
private async void PingSelected_Click(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
try { await _vm.PingSelectedAsync(); }
|
||||
catch (Exception ex) { await MessageBoxAsync(ex.Message); }
|
||||
}
|
||||
|
||||
private async void StartWork_Click(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
try { await _vm.StartWorkSelectedAsync(); }
|
||||
catch (Exception ex) { await MessageBoxAsync(ex.Message); }
|
||||
}
|
||||
|
||||
private async void CancelWork_Click(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
try { await _vm.CancelWorkSelectedAsync(); }
|
||||
catch (Exception ex) { await MessageBoxAsync(ex.Message); }
|
||||
}
|
||||
|
||||
private async Task MessageBoxAsync(string message)
|
||||
{
|
||||
var dlg = new Window
|
||||
{
|
||||
Title = "Error",
|
||||
Width = 500,
|
||||
Height = 160,
|
||||
Content = new StackPanel
|
||||
{
|
||||
Margin = new Avalonia.Thickness(12),
|
||||
Spacing = 12,
|
||||
Children =
|
||||
{
|
||||
new TextBlock { Text = message, TextWrapping = Avalonia.Media.TextWrapping.Wrap },
|
||||
new Button
|
||||
{
|
||||
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right,
|
||||
Content = "OK",
|
||||
IsDefault = true
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (dlg.Content is StackPanel sp && sp.Children.LastOrDefault() is Button ok)
|
||||
{
|
||||
ok.Click += (_, __) => dlg.Close();
|
||||
}
|
||||
|
||||
await dlg.ShowDialog(this);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user