Skip to content

Commit 5e9ea16

Browse files
Add a messagebox
1 parent c9add29 commit 5e9ea16

File tree

5 files changed

+159
-0
lines changed

5 files changed

+159
-0
lines changed

WatchOnlyBitcoinWallet/AllEnums.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// WatchOnlyBitcoinWallet
2+
// Copyright (c) 2016 Coding Enthusiast
3+
// Distributed under the MIT software license, see the accompanying
4+
// file LICENCE or http://www.opensource.org/licenses/mit-license.php.
5+
6+
namespace WatchOnlyBitcoinWallet
7+
{
8+
public enum MessageBoxType
9+
{
10+
Ok,
11+
OkCancel,
12+
YesNo,
13+
}
14+
15+
16+
public enum MessageBoxResult
17+
{
18+
Ok,
19+
Cancel,
20+
Yes,
21+
No
22+
}
23+
}
1.83 KB
Loading
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// WatchOnlyBitcoinWallet
2+
// Copyright (c) 2016 Coding Enthusiast
3+
// Distributed under the MIT software license, see the accompanying
4+
// file LICENCE or http://www.opensource.org/licenses/mit-license.php.
5+
6+
using System;
7+
8+
namespace WatchOnlyBitcoinWallet.ViewModels
9+
{
10+
public class MessageBoxViewModel : ViewModelBase
11+
{
12+
public MessageBoxViewModel()
13+
{
14+
Message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et " +
15+
$"dolore magna aliqua. {Environment.NewLine}Ut enim ad minim veniam, quis nostrud exercitation ullamco " +
16+
$"laboris nisi ut aliquip ex ea commodo consequat.";
17+
IsDualCommand = true;
18+
CommandName1 = "cmd1";
19+
CommandName2 = "cmd2";
20+
}
21+
22+
public MessageBoxViewModel(MessageBoxType t, string message)
23+
{
24+
Message = message;
25+
msgType = t;
26+
switch (t)
27+
{
28+
case MessageBoxType.Ok:
29+
CommandName1 = "Ok";
30+
CommandName2 = string.Empty;
31+
IsDualCommand = false;
32+
break;
33+
case MessageBoxType.OkCancel:
34+
CommandName1 = "OK";
35+
CommandName2 = "Cancel";
36+
IsDualCommand = true;
37+
break;
38+
case MessageBoxType.YesNo:
39+
CommandName1 = "Yes";
40+
CommandName2 = "No";
41+
IsDualCommand = true;
42+
break;
43+
default:
44+
throw new NotImplementedException();
45+
}
46+
}
47+
48+
49+
private readonly MessageBoxType msgType;
50+
public string Message { get; }
51+
public bool IsDualCommand { get; }
52+
public string CommandName1 { get; }
53+
public string CommandName2 { get; }
54+
55+
public MessageBoxResult Result { get; private set; }
56+
57+
public void Command1()
58+
{
59+
Result = msgType switch
60+
{
61+
MessageBoxType.Ok => MessageBoxResult.Ok,
62+
MessageBoxType.OkCancel => MessageBoxResult.Ok,
63+
MessageBoxType.YesNo => MessageBoxResult.Yes,
64+
_ => throw new NotImplementedException(),
65+
};
66+
67+
RaiseCloseEvent();
68+
}
69+
70+
public void Command2()
71+
{
72+
Result = msgType switch
73+
{
74+
MessageBoxType.Ok => throw new Exception("This should never happen."),
75+
MessageBoxType.OkCancel => MessageBoxResult.Cancel,
76+
MessageBoxType.YesNo => MessageBoxResult.No,
77+
_ => throw new NotImplementedException(),
78+
};
79+
80+
RaiseCloseEvent();
81+
}
82+
}
83+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<UserControl xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:vm="clr-namespace:WatchOnlyBitcoinWallet.ViewModels"
6+
mc:Ignorable="d"
7+
MaxWidth="400"
8+
x:Class="WatchOnlyBitcoinWallet.Views.MessageBoxView">
9+
10+
<Design.DataContext>
11+
<vm:MessageBoxViewModel/>
12+
</Design.DataContext>
13+
14+
<Grid RowDefinitions="*,auto">
15+
<Grid ColumnDefinitions="auto,*" Grid.Row="0">
16+
<Image Source="/Assets/Attention.png"
17+
Width="40"
18+
Margin="5"
19+
Grid.Column="0"/>
20+
<TextBlock Text="{Binding Message}"
21+
TextWrapping="Wrap"
22+
Margin="10"
23+
Grid.Column="1"/>
24+
</Grid>
25+
26+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Spacing="10" Margin="5" Grid.Row="1">
27+
<Button Content="{Binding CommandName1}"
28+
Command="{Binding Command1}"
29+
Height="30" Width="65"/>
30+
<Button Content="{Binding CommandName2}"
31+
Command="{Binding Command2}"
32+
IsVisible="{Binding IsDualCommand}"
33+
Height="30" Width="65"/>
34+
</StackPanel>
35+
</Grid>
36+
</UserControl>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// WatchOnlyBitcoinWallet
2+
// Copyright (c) 2016 Coding Enthusiast
3+
// Distributed under the MIT software license, see the accompanying
4+
// file LICENCE or http://www.opensource.org/licenses/mit-license.php.
5+
6+
using Avalonia.Controls;
7+
8+
namespace WatchOnlyBitcoinWallet.Views
9+
{
10+
public partial class MessageBoxView : UserControl
11+
{
12+
public MessageBoxView()
13+
{
14+
InitializeComponent();
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)