From 5c76b8ec52314108eb578853bd63273ba8a57fab Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Wed, 26 Jun 2024 19:04:43 +0200 Subject: [PATCH] PaymentAdjustmentWindow: Improve DataGrid and add status bar --- Elwig/Controls/UnitConverter.cs | 41 +++++ Elwig/Windows/PaymentAdjustmentWindow.xaml | 167 ++++++++++++++---- Elwig/Windows/PaymentAdjustmentWindow.xaml.cs | 74 ++++++-- 3 files changed, 239 insertions(+), 43 deletions(-) create mode 100644 Elwig/Controls/UnitConverter.cs diff --git a/Elwig/Controls/UnitConverter.cs b/Elwig/Controls/UnitConverter.cs new file mode 100644 index 0000000..1066804 --- /dev/null +++ b/Elwig/Controls/UnitConverter.cs @@ -0,0 +1,41 @@ +using System; +using System.Globalization; +using System.Windows; +using System.Windows.Data; + +namespace Elwig.Controls { + public class UnitConverter : DependencyObject, IValueConverter { + + public static readonly DependencyProperty UnitProperty = DependencyProperty.Register("Unit", typeof(string), typeof(UnitConverter), new FrameworkPropertyMetadata(null)); + public string Unit { + get => (string)GetValue(UnitProperty); + set => SetValue(UnitProperty, value); + } + + public static readonly DependencyProperty PrecisionProperty = DependencyProperty.Register("Precision", typeof(byte), typeof(UnitConverter), new FrameworkPropertyMetadata((byte)0)); + public byte Precision { + get => (byte)GetValue(PrecisionProperty); + set => SetValue(PrecisionProperty, value); + } + + public object? Convert(object? value, Type targetType, object parameter, CultureInfo culture) { + if (value == null) { + return null; + } + + var fmt = $"{{0:N{Precision}}}"; + var unit = $"{(Unit != null ? " " : "")}{Unit}"; + if (value is int i) { + return $"{string.Format(fmt, i)}{unit}"; + } else if (value is decimal d) { + return $"{string.Format(fmt, d)}{unit}"; + } + + return Binding.DoNothing; + } + + public object? ConvertBack(object? value, Type targetType, object parameter, CultureInfo culture) { + throw new NotImplementedException(); + } + } +} diff --git a/Elwig/Windows/PaymentAdjustmentWindow.xaml b/Elwig/Windows/PaymentAdjustmentWindow.xaml index 193626b..3a691a0 100644 --- a/Elwig/Windows/PaymentAdjustmentWindow.xaml +++ b/Elwig/Windows/PaymentAdjustmentWindow.xaml @@ -6,8 +6,10 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:Elwig.Windows" xmlns:ctrl="clr-namespace:Elwig.Controls" - Title="Auszahlung anpassen - Elwig" Height="500" Width="850" MinHeight="400" MinWidth="850"> + Title="Auszahlung anpassen - Elwig" Height="600" Width="1000" MinHeight="400" MinWidth="850"> + + + @@ -63,22 +74,50 @@ - - + + - + - + + + + + + + + + + + + + + + + + + + + +