bloxstrap/Bloxstrap/UI/Elements/Dialogs/ConnectivityDialog.xaml.cs
pizzaboxer 6eebb54435
Push all changes made to ConnectivityDialog
this was part of b2cfeeb, i dont know how this somehow managed to evade being added
2024-07-05 10:24:57 +04:00

54 lines
1.5 KiB
C#

using System.Media;
using System.Windows.Interop;
using Windows.Win32;
using Windows.Win32.Foundation;
namespace Bloxstrap.UI.Elements.Dialogs
{
// hmm... do i use MVVM for this?
// this is entirely static, so i think im fine without it, and this way is just so much more efficient
/// <summary>
/// Interaction logic for ExceptionDialog.xaml
/// </summary>
public partial class ConnectivityDialog
{
public ConnectivityDialog(string title, string description, Exception exception)
{
InitializeComponent();
TitleTextBlock.Text = title;
DescriptionTextBlock.MarkdownText = description;
AddException(exception);
CloseButton.Click += delegate
{
Close();
};
SystemSounds.Hand.Play();
Loaded += delegate
{
var hWnd = new WindowInteropHelper(this).Handle;
PInvoke.FlashWindow((HWND)hWnd, true);
};
}
private void AddException(Exception exception, bool inner = false)
{
if (!inner)
ErrorRichTextBox.Selection.Text = $"{exception.GetType()}: {exception.Message}";
if (exception.InnerException is null)
return;
ErrorRichTextBox.Selection.Text += $"\n\n[Inner Exception]\n{exception.InnerException.GetType()}: {exception.InnerException.Message}";
AddException(exception.InnerException, true);
}
}
}