This commit is contained in:
Meik
2025-11-11 11:03:42 +01:00
commit dc3e8a2e4c
582 changed files with 191465 additions and 0 deletions

View File

@@ -0,0 +1,122 @@
<p:CustomPopupBase x:Class="FasdDesktopUi.Pages.CustomMessageBox.CustomMessageBox"
xmlns:p="clr-namespace:FasdDesktopUi.Pages"
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:local="clr-namespace:FasdDesktopUi.Pages.CustomMessageBox"
xmlns:uc="clr-namespace:FasdDesktopUi.Basics.UserControls"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:ico="clr-namespace:FasdDesktopUi.Basics.UserControls.AdaptableIcon;assembly=F4SD-AdaptableIcon"
xmlns:vc="clr-namespace:FasdDesktopUi.Basics.Converter"
mc:Ignorable="d"
x:Name="CustomMessageBoxView"
AllowsTransparency="True"
WindowStyle="None"
ResizeMode="NoResize"
SizeToContent="Height"
MaxWidth="475"
Background="Transparent"
WindowStartupLocation="CenterOwner"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
PreviewKeyDown="CustomMessageBox_PreviewKeyDown"
IsVisibleChanged="BlurInvoker_IsActiveChanged"
>
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="40" />
</WindowChrome.WindowChrome>
<p:CustomPopupBase.Resources>
<BooleanToVisibilityConverter x:Key="BoolToVisibility" />
<vc:NullValueToVisibilityConverter x:Key="NullToVisibility" />
<vc:BoolOrToVisibilityConverter x:Key="BoolOrToVisibilityConverter" />
</p:CustomPopupBase.Resources>
<Border Background="{DynamicResource BackgroundColor.Menu.Categories}"
CornerRadius="7.5"
Padding="10">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Canvas Grid.RowSpan="999"
Panel.ZIndex="5"
Margin="-10 -10">
<Border x:Name="FocusBorder"
Background="{DynamicResource Color.BlurBorder}"
Grid.RowSpan="999"
Opacity="0.4"
Visibility="Collapsed"
Panel.ZIndex="-1"
Width="{Binding ElementName=CustomMessageBoxView, Path=ActualWidth}"
Height="{Binding ElementName=CustomMessageBoxView, Path=ActualHeight}" />
<Decorator x:Name="FocusDecorator" />
</Canvas>
<DockPanel Grid.Row="0"
Margin="0 0 0 10"
>
<ico:AdaptableIcon DockPanel.Dock="Right"
HorizontalAlignment="Right"
Style="{DynamicResource SettingsPage.Close.Icon}"
MouseLeftButtonUp="Close_MouseLeftButtonUp"
TouchDown="Close_TouchDown"
SelectedInternIcon="window_close" />
<ico:AdaptableIcon x:Name="StatusIcon"
DockPanel.Dock="Left"
SecondaryIconColor="{DynamicResource Color.AppBackground}"
HorizontalAlignment="Right"
BorderPadding="0 7.5 7.5 7.5"
Visibility="Collapsed">
</ico:AdaptableIcon>
<TextBlock Text="{Binding Caption}"
TextTrimming="CharacterEllipsis"
FontSize="18"
VerticalAlignment="Center"
FontFamily="Calibri"
FontWeight="Bold"
Foreground="{DynamicResource FontColor.SlimPage.WidgetCollection.Header}"
Visibility="{Binding Caption, Converter={StaticResource NullToVisibility}}"/>
</DockPanel>
<Border Grid.Row="1" Background="{DynamicResource BackgroundColor.Menu.MainCategory}"
CornerRadius="7.5"
Padding="10"
Visibility="{Binding Message, Converter={StaticResource NullToVisibility}}">
<TextBlock Text="{Binding Message}"
FontSize="16"
TextWrapping="Wrap"
Visibility="{Binding Message, Converter={StaticResource NullToVisibility}}"
Style="{DynamicResource SlimPage.Widget.Title}" />
</Border>
<uc:YesNoButton x:Name="YesNoButtonControl" x:FieldModifier="private"
Grid.Row="2"
HasYesNoButtons="{Binding ElementName=CustomMessageBoxView, Path=HasYesNoButtons}"
HasYesNoText="{Binding ElementName=CustomMessageBoxView, Path=HasYesNoText}"
ButtonHasBeenClicked="YesNoButton_ButtonHasBeenClicked"
>
<uc:YesNoButton.Visibility>
<MultiBinding Converter="{StaticResource BoolOrToVisibilityConverter}">
<Binding Path="HasYesNoButtons" ElementName="CustomMessageBoxView"/>
<Binding Path="HasYesNoText" ElementName="CustomMessageBoxView"/>
</MultiBinding>
</uc:YesNoButton.Visibility>
</uc:YesNoButton>
<uc:MultiButton HorizontalAlignment="Center"
x:Name="MultiButtons"
Grid.Row="2"
Visibility="Collapsed" ResultChanged="MultiButtons_ResultChanged"
Margin="0,10,0,0"
>
</uc:MultiButton>
</Grid>
</Border>
</p:CustomPopupBase>

View File

@@ -0,0 +1,343 @@
using C4IT.FASD.Base;
using F4SD_AdaptableIcon.Enums;
using FasdDesktopUi.Basics;
using FasdDesktopUi.Basics.CustomEvents;
using FasdDesktopUi.Basics.Models;
using FasdDesktopUi.Basics.UserControls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using static C4IT.Logging.cLogManager;
namespace FasdDesktopUi.Pages.CustomMessageBox
{
public partial class CustomMessageBox : CustomPopupBase, IBlurInvoker, INotifyPropertyChanged
{
#region Properties
private bool isCanceled = false;
#region Caption
private string _Caption = null;
public string Caption
{
get { return _Caption; }
set { if (value != _Caption) { _Caption = value; OnPropertyChanged("Caption"); } }
}
#endregion
#region Message
private string _Message = null;
public string Message
{
get { return _Message; }
set { if (value != _Message) { _Message = value; OnPropertyChanged("Message"); } }
}
#endregion
#region CenterText
private bool _CenterText = false;
public bool CenterText
{
get { return _CenterText; }
set { if (value != _CenterText) { _CenterText = value; OnPropertyChanged("CenterText"); } }
}
#endregion
#region HasYesNoButtons
private bool _HasYesNoButtons = false;
public bool HasYesNoButtons
{
get { return _HasYesNoButtons; }
set { if (value != _HasYesNoButtons) { _HasYesNoButtons = value; OnPropertyChanged("HasYesNoButtons"); } }
}
#endregion
#region HasYesNoText
private bool _HasYesNoText = false;
public bool HasYesNoText
{
get { return _HasYesNoText; }
set { if (value != _HasYesNoText) { _HasYesNoText = value; OnPropertyChanged("HasYesNoText"); } }
}
#endregion
public event PropertyChangedEventHandler PropertyChanged;
public int ResultIndex { get; private set; } = -1;
protected void OnPropertyChanged([CallerMemberName] string name = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
#endregion
private CustomMessageBox()
{
InitializeComponent();
}
protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
cFocusInvoker.GotFocus += ElementGotFocus;
cFocusInvoker.LostFocus += ElementLostFocus;
}
private void SetLevel(enumHealthCardStateLevel level)
{
StatusIcon.Visibility = Visibility.Visible;
switch (level)
{
case enumHealthCardStateLevel.None:
StatusIcon.Visibility = Visibility.Collapsed;
StatusIcon.SelectedInternIcon = enumInternIcons.none;
break;
case enumHealthCardStateLevel.Ok:
StatusIcon.SelectedInternIcon = enumInternIcons.status_good;
StatusIcon.PrimaryIconColor = (SolidColorBrush)Application.Current.FindResource("Color.Green");
break;
case enumHealthCardStateLevel.Warning:
StatusIcon.SelectedInternIcon = enumInternIcons.status_danger;
StatusIcon.PrimaryIconColor = (SolidColorBrush)Application.Current.FindResource("Color.Orange");
break;
case enumHealthCardStateLevel.Error:
StatusIcon.SelectedInternIcon = enumInternIcons.status_bad;
StatusIcon.PrimaryIconColor = (SolidColorBrush)Application.Current.FindResource("Color.Red");
break;
case enumHealthCardStateLevel.Info:
StatusIcon.SelectedInternIcon = enumInternIcons.status_info;
StatusIcon.PrimaryIconColor = (SolidColorBrush)Application.Current.FindResource("Color.Blue");
break;
default:
StatusIcon.SelectedInternIcon = enumInternIcons.f4sd;
break;
}
}
private static CustomMessageBox InitializeMessageBox(string Message, string Caption, enumHealthCardStateLevel Level, Window Owner, bool HasYesNoButtons, bool HasYesNoText, List<string> MultiButtonText, bool TopMost, bool CenterScreen)
{
try
{
if (Owner != null)
cUtility.BringWindowToFront(Owner);
var existingMessageBox = Application.Current.Windows.Cast<Window>().FirstOrDefault(window => window is CustomMessageBox);
if (existingMessageBox != null)
{
existingMessageBox.Show();
return null;
}
CustomMessageBox messageBox = new CustomMessageBox();
if (MultiButtonText != null)
{
HasYesNoButtons = false;
HasYesNoText = false;
messageBox.MultiButtons.Visibility = Visibility.Visible;
messageBox.MultiButtons.SetButtonText(MultiButtonText);
}
messageBox.Message = Message;
messageBox.Caption = Caption;
messageBox.SetLevel(Level);
messageBox.HasYesNoButtons = HasYesNoButtons;
messageBox.HasYesNoText = HasYesNoText;
messageBox.Topmost = TopMost;
try
{
messageBox.Owner = Owner;
}
catch { }
if (!CenterScreen && Owner != null && Owner.Visibility == Visibility.Visible)
messageBox.WindowStartupLocation = WindowStartupLocation.CenterOwner;
else
messageBox.WindowStartupLocation = WindowStartupLocation.CenterScreen;
return messageBox;
}
catch (Exception E)
{
LogException(E);
}
return null;
}
public static int Show(string Message, List<string> MultiButtonText, string Caption = null, enumHealthCardStateLevel Level = enumHealthCardStateLevel.None, Window Owner = null, bool TopMost = false, bool CenterScreen = false, int MaxWidth = -1)
{
var messageBox = InitializeMessageBox(Message, Caption, Level, Owner, false, false, MultiButtonText, TopMost, CenterScreen);
if (MaxWidth > 0)
messageBox.MaxWidth = MaxWidth;
if (messageBox == null)
return -1;
messageBox.ShowDialog();
return messageBox.ResultIndex;
}
public static bool? Show(string Message, string Caption = null, enumHealthCardStateLevel Level = enumHealthCardStateLevel.None, Window Owner = null, bool HasYesNoButtons = false, bool HasYesNoText = false, bool TopMost = false, bool CenterScreen = false)
{
var messageBox = InitializeMessageBox(Message, Caption, Level, Owner, HasYesNoButtons, HasYesNoText, null, TopMost, CenterScreen);
if (messageBox == null)
return null;
var dialogResult = messageBox.ShowDialog();
return messageBox.isCanceled ? null : dialogResult;
}
#region Close_Click
private void Close_Click()
{
DialogResult = null;
isCanceled = true;
Close();
}
private void Close_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
Close_Click();
}
private void Close_TouchDown(object sender, TouchEventArgs e)
{
Close_Click();
}
#endregion
#region Internal Focus Events
private void ElementGotFocus(object sender, EventArgs e)
{
try
{
FocusBorder.Visibility = Visibility.Visible;
if (!(sender is FrameworkElement senderElement))
return;
if (FocusBorder.IsVisible is false)
return;
var desiredHeight = senderElement.ActualHeight;
var desiredWidth = senderElement.ActualWidth;
FrameworkElement placeHolderElement = new FrameworkElement() { Height = desiredHeight, Width = desiredWidth, Margin = senderElement.Margin };
FocusDecorator.Height = desiredHeight + senderElement.Margin.Top + senderElement.Margin.Bottom;
FocusDecorator.Width = desiredWidth + senderElement.Margin.Left + senderElement.Margin.Right;
Point relativePoint = senderElement.TransformToAncestor(this)
.Transform(new Point(0, 0));
if (senderElement.Parent is Decorator actualParentDecorator)
actualParentDecorator.Child = placeHolderElement;
else if (senderElement.Parent is Panel actualParentPanel)
{
if (actualParentPanel is Grid)
{
Grid.SetColumn(placeHolderElement, Grid.GetColumn(senderElement));
Grid.SetRow(placeHolderElement, Grid.GetRow(senderElement));
}
actualParentPanel.Children.Insert(actualParentPanel.Children.IndexOf(senderElement), placeHolderElement);
actualParentPanel.Children.Remove(senderElement);
}
Canvas.SetLeft(FocusDecorator, relativePoint.X - (senderElement.Margin.Left));
Canvas.SetTop(FocusDecorator, relativePoint.Y - senderElement.Margin.Top);
FocusDecorator.Child = senderElement;
}
catch (Exception E)
{
LogException(E);
}
}
private void ElementLostFocus(object sender, EventArgs e)
{
try
{
FocusBorder.Visibility = Visibility.Collapsed;
}
catch (Exception E)
{
LogException(E);
}
}
#endregion
private void CustomMessageBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Escape:
Close_Click();
break;
}
}
private void DoCloseAction(bool IsClose)
{
DialogResult = IsClose;
Close();
return;
}
private void YesNoButton_ButtonHasBeenClicked(object sender, BooleanEventArgs e)
{
try
{
DoCloseAction(e.BooleanArg);
}
catch (Exception E)
{
LogException(E);
}
}
private void MultiButtons_ResultChanged(object sender, MultiButtonEventArgs e)
{
ResultIndex = e.ResultIndex;
Close();
}
public override void Dispose()
{
base.Dispose();
Close();
}
}
}