diff --git a/FasdDesktopUi/Basics/UserControls/Ticket/CloseCaseDialogWithTicket.xaml b/FasdDesktopUi/Basics/UserControls/Ticket/CloseCaseDialogWithTicket.xaml index dd4ab18..787b8d9 100644 --- a/FasdDesktopUi/Basics/UserControls/Ticket/CloseCaseDialogWithTicket.xaml +++ b/FasdDesktopUi/Basics/UserControls/Ticket/CloseCaseDialogWithTicket.xaml @@ -88,7 +88,6 @@ diff --git a/FasdDesktopUi/Basics/UserControls/Ticket/CloseCaseDialogWithTicket.xaml.cs b/FasdDesktopUi/Basics/UserControls/Ticket/CloseCaseDialogWithTicket.xaml.cs index d8353a2..06671a6 100644 --- a/FasdDesktopUi/Basics/UserControls/Ticket/CloseCaseDialogWithTicket.xaml.cs +++ b/FasdDesktopUi/Basics/UserControls/Ticket/CloseCaseDialogWithTicket.xaml.cs @@ -2736,6 +2736,23 @@ namespace FasdDesktopUi.Basics.UserControls } } + public void SetDialogContentMaxHeight(double maxHeight) + { + try + { + if (DialogContentScrollViewer == null) + return; + + // Keep dialog usable on very small screens, but allow larger monitors to use space. + var clamped = Math.Max(220, Math.Min(900, maxHeight)); + DialogContentScrollViewer.MaxHeight = clamped; + } + catch (Exception E) + { + LogException(E); + } + } + private void DropDownClosed(object sender, EventArgs e) { if (!(sender is FrameworkElement fe)) return; diff --git a/FasdDesktopUi/Pages/TicketCompletion/TicketCompletion.xaml.cs b/FasdDesktopUi/Pages/TicketCompletion/TicketCompletion.xaml.cs index e9be7c8..abaf444 100644 --- a/FasdDesktopUi/Pages/TicketCompletion/TicketCompletion.xaml.cs +++ b/FasdDesktopUi/Pages/TicketCompletion/TicketCompletion.xaml.cs @@ -3,13 +3,16 @@ using FasdDesktopUi.Basics; using FasdDesktopUi.Basics.Models; using System; using System.ComponentModel; -using System.Linq; -using System.Reflection; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Input; -using static C4IT.Logging.cLogManager; +using System.Linq; +using System.Reflection; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using System.Windows.Interop; +using System.Windows.Media; +using WinForms = System.Windows.Forms; +using static C4IT.Logging.cLogManager; namespace FasdDesktopUi.Pages.TicketCompletion { @@ -42,13 +45,25 @@ namespace FasdDesktopUi.Pages.TicketCompletion CloseCaseDialogUc.DataProvider = _dataProvider; } - protected override void OnInitialized(EventArgs e) - { - base.OnInitialized(e); - - cFocusInvoker.GotFocus += ElementGotFocus; - cFocusInvoker.LostFocus += ElementLostFocus; - } + protected override void OnInitialized(EventArgs e) + { + base.OnInitialized(e); + + cFocusInvoker.GotFocus += ElementGotFocus; + cFocusInvoker.LostFocus += ElementLostFocus; + } + + protected override void OnSourceInitialized(EventArgs e) + { + base.OnSourceInitialized(e); + UpdateDialogMaxHeightToScreen(); + } + + protected override void OnLocationChanged(EventArgs e) + { + base.OnLocationChanged(e); + UpdateDialogMaxHeightToScreen(); + } #region ClosingBusy @@ -126,6 +141,38 @@ namespace FasdDesktopUi.Pages.TicketCompletion } } + private void UpdateDialogMaxHeightToScreen() + { + try + { + WinForms.Screen screen = null; + IntPtr currentHandle = new WindowInteropHelper(this).Handle; + + if (currentHandle != IntPtr.Zero) + { + screen = WinForms.Screen.FromHandle(currentHandle); + } + else if (Owner != null) + { + IntPtr ownerHandle = new WindowInteropHelper(Owner).Handle; + if (ownerHandle != IntPtr.Zero) + screen = WinForms.Screen.FromHandle(ownerHandle); + } + + screen = screen ?? WinForms.Screen.PrimaryScreen; + var workingArea = screen?.WorkingArea ?? WinForms.Screen.PrimaryScreen.WorkingArea; + var dpiScaleY = VisualTreeHelper.GetDpi(this).DpiScaleY; + var maxHeightDip = (workingArea.Height / Math.Max(0.1, dpiScaleY)) - 12; + + MaxHeight = Math.Max(220, maxHeightDip); + CloseCaseDialogUc?.SetDialogContentMaxHeight(MaxHeight - 180); + } + catch (Exception ex) + { + LogException(ex); + } + } + #region Internal Focus Events private void ElementGotFocus(object sender, EventArgs e)