From 4d89e49c9639c395fc981474a3450bee1190e10f Mon Sep 17 00:00:00 2001 From: Michael Babienco Date: Wed, 8 Apr 2026 22:16:56 +0900 Subject: [PATCH] Use multibinding for receipt date format --- src/Helpers/DateFormatConverter.cs | 27 +++++++++++++++++++++++++++ src/Views/MainView.axaml | 15 ++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 src/Helpers/DateFormatConverter.cs diff --git a/src/Helpers/DateFormatConverter.cs b/src/Helpers/DateFormatConverter.cs new file mode 100644 index 0000000..47b21c5 --- /dev/null +++ b/src/Helpers/DateFormatConverter.cs @@ -0,0 +1,27 @@ + +using System; +using System.Collections.Generic; +using System.Globalization; +using Avalonia.Data.Converters; + +namespace MayShow.Helpers; + +public class DateFormatConverter : IMultiValueConverter +{ + public object? Convert( + IList values, + Type targetType, + object? parameter, + CultureInfo culture) + { + if (values.Count >= 2 && values[0] is DateOnly date && values[1] is string format) + { + return date.ToString(format); + } + if (values.Count >= 2 && values[0] is string dateFormat && values[1] is DateOnly dateOnly) + { + return dateOnly.ToString(dateFormat); + } + return 0.0; + } +} \ No newline at end of file diff --git a/src/Views/MainView.axaml b/src/Views/MainView.axaml index d83fa8e..a5487a9 100644 --- a/src/Views/MainView.axaml +++ b/src/Views/MainView.axaml @@ -10,6 +10,9 @@ xmlns:vm="clr-namespace:MayShow.ViewModels" xmlns:progRing="clr-namespace:AvaloniaProgressRing;assembly=AvaloniaProgressRing" x:DataType="vm:MainViewModel"> + + +