Generelle Ausnahmenanzeige

This commit is contained in:
2023-03-03 21:23:48 +01:00
parent 101ce32c06
commit 6ea4a47b98
18 changed files with 1226 additions and 1346 deletions

View File

@@ -2,6 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ownChat"
DispatcherUnhandledException="App_DispatcherUnhandledException"
StartupUri="LoginMaske.xaml">
<Application.Resources>

View File

@@ -1,6 +1,14 @@
namespace ownChat
using System.Windows.Threading;
namespace ownChat
{
public partial class App
{
private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs args)
{
new ExceptionWindow(args.Exception) { Owner = MainWindow }.Show();
args.Handled = true;
}
}
}

View File

@@ -0,0 +1,12 @@
<Window x:Class="ownChat.ExceptionWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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:chatController="clr-namespace:ChatController;assembly=ChatController"
mc:Ignorable="d" WindowStartupLocation="CenterOwner"
Title="Es ist ein Fehler aufgetreten" Height="450" Width="800">
<Grid>
<chatController:ExceptionViewControl x:Name="ExceptionViewControl" OkButtonClicked="ExceptionViewControl_OnOkButtonClicked" />
</Grid>
</Window>

View File

@@ -0,0 +1,18 @@
using System;
namespace ownChat
{
public partial class ExceptionWindow
{
public ExceptionWindow(Exception exception)
{
InitializeComponent();
ExceptionViewControl.Exception = exception;
}
private void ExceptionViewControl_OnOkButtonClicked(object sender, EventArgs e)
{
Close();
}
}
}

View File

@@ -17,6 +17,9 @@ namespace ownChat
{
InitializeComponent();
var currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += ExceptionHandler;
ChatMainControl.ContainingWindow = this;
ChatMainControl.InitMitChatdaten(x);
@@ -24,6 +27,13 @@ namespace ownChat
_EmojiView = new ChatEmojisView(ChatMainControl);
}
private void ExceptionHandler(object sender, UnhandledExceptionEventArgs args)
{
var exception = (Exception)args.ExceptionObject;
new ExceptionWindow(exception) { Owner = this }.Show();
}
private void ChatMainControl_OnOnEmojii(System.Windows.Controls.Button emojiButton)
{
_EmojiView.Visibility = Visibility.Visible;
@@ -31,11 +41,13 @@ namespace ownChat
var pointToScreen = emojiButton.PointToScreen(new Point(0, 0));
var presentationSource = PresentationSource.FromVisual(emojiButton);
if(presentationSource?.CompositionTarget != null)
if(presentationSource?.CompositionTarget == null)
{
_EmojiView.Top = pointToScreen.Y / presentationSource.CompositionTarget.TransformToDevice.M22 - _EmojiView.Height - 5;
_EmojiView.Left = pointToScreen.X / presentationSource.CompositionTarget.TransformToDevice.M11 - 270;
return;
}
_EmojiView.Top = pointToScreen.Y / presentationSource.CompositionTarget.TransformToDevice.M22 - _EmojiView.Height - 5;
_EmojiView.Left = pointToScreen.X / presentationSource.CompositionTarget.TransformToDevice.M11 - 270;
}
private void MainWindow_OnClosed(object sender, EventArgs e)

View File

@@ -105,6 +105,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ExceptionWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="LoginMaske.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@@ -117,6 +121,9 @@
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="ExceptionWindow.xaml.cs">
<DependentUpon>ExceptionWindow.xaml</DependentUpon>
</Compile>
<Compile Include="LoginMaske.xaml.cs">
<DependentUpon>LoginMaske.xaml</DependentUpon>
</Compile>