Skip to content

Commit

Permalink
Add a MessageBox
Browse files Browse the repository at this point in the history
  • Loading branch information
Coding-Enthusiast committed May 3, 2024
1 parent 8a6c914 commit 5bae762
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 0 deletions.
Binary file added Src/Denovo/Assets/Attention.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions Src/Denovo/Models/AllEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ public enum ClientType
SpvElectrum
}

public enum MessageBoxResult
{
Ok,
Cancel,
Yes,
No
}

public enum MessageBoxType
{
Ok,
OkCancel,
YesNo,
}

public enum PeerDiscoveryOption
{
DNS,
Expand Down
83 changes: 83 additions & 0 deletions Src/Denovo/ViewModels/MessageBoxViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Denovo
// Copyright (c) 2020 Autarkysoft
// Distributed under the MIT software license, see the accompanying
// file LICENCE or http://www.opensource.org/licenses/mit-license.php.

using Denovo.Models;
using System;

namespace Denovo.ViewModels
{
public class MessageBoxViewModel : ViewModelBase
{
public MessageBoxViewModel()
{
Message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et " +
$"dolore magna aliqua. {Environment.NewLine}Ut enim ad minim veniam, quis nostrud exercitation ullamco " +
$"laboris nisi ut aliquip ex ea commodo consequat.";
IsDualCommand = true;
CommandName1 = "cmd1";
CommandName2 = "cmd2";
}

public MessageBoxViewModel(MessageBoxType t, string message)
{
Message = message;
msgType = t;
switch (t)
{
case MessageBoxType.Ok:
CommandName1 = "Ok";
IsDualCommand = false;
break;
case MessageBoxType.OkCancel:
CommandName1 = "OK";
CommandName2 = "Cancel";
IsDualCommand = true;
break;
case MessageBoxType.YesNo:
CommandName1 = "Yes";
CommandName2 = "No";
IsDualCommand = true;
break;
default:
throw new NotImplementedException();
}
}


private readonly MessageBoxType msgType;
public string Message { get; }
public bool IsDualCommand { get; }
public string CommandName1 { get; }
public string CommandName2 { get; }

public MessageBoxResult Result { get; private set; }

public void Command1()
{
Result = msgType switch
{
MessageBoxType.Ok => MessageBoxResult.Ok,
MessageBoxType.OkCancel => MessageBoxResult.Ok,
MessageBoxType.YesNo => MessageBoxResult.Yes,
_ => throw new NotImplementedException(),
};

RaiseCloseEvent();
}

public void Command2()
{
Result = msgType switch
{
MessageBoxType.Ok => throw new Exception("This should never happen."),
MessageBoxType.OkCancel => MessageBoxResult.Cancel,
MessageBoxType.YesNo => MessageBoxResult.No,
_ => throw new NotImplementedException(),
};

RaiseCloseEvent();
}
}
}
38 changes: 38 additions & 0 deletions Src/Denovo/Views/MessageBoxView.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:Denovo.ViewModels;assembly=Denovo"
mc:Ignorable="d"
x:CompileBindings="True"
x:DataType="vm:MessageBoxViewModel"
MaxWidth="400"
x:Class="Denovo.Views.MessageBoxView">

<Design.DataContext>
<vm:MessageBoxViewModel/>
</Design.DataContext>

<Grid RowDefinitions="*,auto">
<Grid ColumnDefinitions="auto,*" Grid.Row="0">
<Image Source="/Assets/Attention.png"
Width="40"
Margin="5"
Grid.Column="0"/>
<TextBlock Text="{Binding Message}"
TextWrapping="Wrap"
Margin="10"
Grid.Column="1"/>
</Grid>

<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Spacing="10" Margin="5" Grid.Row="1">
<Button Content="{Binding CommandName1}"
Command="{Binding Command1}"
Height="30" Width="65"/>
<Button Content="{Binding CommandName2}"
Command="{Binding Command2}"
IsVisible="{Binding IsDualCommand}"
Height="30" Width="65"/>
</StackPanel>
</Grid>
</UserControl>
17 changes: 17 additions & 0 deletions Src/Denovo/Views/MessageBoxView.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Denovo
// Copyright (c) 2020 Autarkysoft
// Distributed under the MIT software license, see the accompanying
// file LICENCE or http://www.opensource.org/licenses/mit-license.php.

using Avalonia.Controls;

namespace Denovo.Views
{
public partial class MessageBoxView : UserControl
{
public MessageBoxView()
{
InitializeComponent();
}
}
}

0 comments on commit 5bae762

Please sign in to comment.