aboutsummaryrefslogtreecommitdiff
path: root/Erable/Views
diff options
context:
space:
mode:
Diffstat (limited to 'Erable/Views')
-rw-r--r--Erable/Views/MainWindow.axaml4
-rw-r--r--Erable/Views/MessageBox.axaml19
-rw-r--r--Erable/Views/MessageBox.axaml.cs74
3 files changed, 96 insertions, 1 deletions
diff --git a/Erable/Views/MainWindow.axaml b/Erable/Views/MainWindow.axaml
index 6bb4cd1..02d362a 100644
--- a/Erable/Views/MainWindow.axaml
+++ b/Erable/Views/MainWindow.axaml
@@ -4,7 +4,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
- x:Class="Erable.Views.MainWindow"
+ x:Class="Erable.Views.MainWindow"
Icon="/Assets/avalonia-logo.ico"
Title="Erable">
@@ -16,5 +16,7 @@
<Button Name="PlayButton" Width="80" Command="{Binding PlayFunction}" >Play</Button>
<Button Name="StopButton" Width="80" >Stop</Button>
<Button Name="BrowseButton" Width="80" Command="{Binding BrowseFunction }" >Browse</Button>
+ <Button Name="MessageBoxTest" Width="80" Command="{Binding MsgBoxTest }" >Message Box Test</Button>
+
</StackPanel>
</Window>
diff --git a/Erable/Views/MessageBox.axaml b/Erable/Views/MessageBox.axaml
new file mode 100644
index 0000000..459817a
--- /dev/null
+++ b/Erable/Views/MessageBox.axaml
@@ -0,0 +1,19 @@
+<Window xmlns="https://github.com/avaloniaui"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:vm="using:Erable.ViewModels"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+ x:Class="Erable.Views.MessageBox" SizeToContent="WidthAndHeight" CanResize="False">
+ <StackPanel HorizontalAlignment="Center">
+ <TextBlock HorizontalAlignment="Center" Name="Text"/>
+ <StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Name="Buttons">
+ <StackPanel.Styles>
+ <Style Selector="Button">
+ <Setter Property="Margin" Value="5"/>
+ </Style>
+ </StackPanel.Styles>
+
+ </StackPanel>
+ </StackPanel>
+</Window> \ No newline at end of file
diff --git a/Erable/Views/MessageBox.axaml.cs b/Erable/Views/MessageBox.axaml.cs
new file mode 100644
index 0000000..6d8b6d9
--- /dev/null
+++ b/Erable/Views/MessageBox.axaml.cs
@@ -0,0 +1,74 @@
+using System.Threading.Tasks;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+
+namespace Erable.Views
+{
+ public class MessageBox : Window
+ {
+ public enum MessageBoxButtons
+ {
+ Ok,
+ OkCancel,
+ YesNo,
+ YesNoCancel
+ }
+
+ public enum MessageBoxResult
+ {
+ Ok,
+ Cancel,
+ Yes,
+ No
+ }
+
+
+ public MessageBox()
+ {
+ AvaloniaXamlLoader.Load(this);
+ }
+
+ public static Task<MessageBoxResult> Show(Window parent, string text, string title, MessageBoxButtons buttons)
+ {
+ var msgbox = new MessageBox()
+ {
+ Title = title
+ };
+ msgbox.FindControl<TextBlock>("Text").Text = text;
+ var buttonPanel = msgbox.FindControl<StackPanel>("Buttons");
+
+ var res = MessageBoxResult.Ok;
+
+ void AddButton(string caption, MessageBoxResult r, bool def = false)
+ {
+ var btn = new Button {Content = caption};
+ btn.Click += (_, __) => {
+ res = r;
+ msgbox.Close();
+ };
+ buttonPanel.Children.Add(btn);
+ if (def)
+ res = r;
+ }
+
+ if (buttons == MessageBoxButtons.Ok || buttons == MessageBoxButtons.OkCancel)
+ AddButton("OK", MessageBoxResult.Ok, true);
+ if (buttons == MessageBoxButtons.YesNo || buttons == MessageBoxButtons.YesNoCancel)
+ {
+ AddButton("Yes", MessageBoxResult.Yes);
+ AddButton("No", MessageBoxResult.No, true);
+ }
+
+ if (buttons == MessageBoxButtons.OkCancel || buttons == MessageBoxButtons.YesNoCancel)
+ AddButton("Cancel", MessageBoxResult.Cancel, true);
+
+
+ var tcs = new TaskCompletionSource<MessageBoxResult>();
+ msgbox.Closed += delegate { tcs.TrySetResult(res); };
+ if (parent != null)
+ msgbox.ShowDialog(parent);
+ else msgbox.Show();
+ return tcs.Task;
+ }
+ }
+} \ No newline at end of file