Use multibinding for receipt date format
This commit is contained in:
@@ -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<object?> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,9 @@
|
|||||||
xmlns:vm="clr-namespace:MayShow.ViewModels"
|
xmlns:vm="clr-namespace:MayShow.ViewModels"
|
||||||
xmlns:progRing="clr-namespace:AvaloniaProgressRing;assembly=AvaloniaProgressRing"
|
xmlns:progRing="clr-namespace:AvaloniaProgressRing;assembly=AvaloniaProgressRing"
|
||||||
x:DataType="vm:MainViewModel">
|
x:DataType="vm:MainViewModel">
|
||||||
|
<UserControl.Resources>
|
||||||
|
<helpers:DateFormatConverter x:Key="DateFormatter" />
|
||||||
|
</UserControl.Resources>
|
||||||
<Grid ColumnDefinitions="*"
|
<Grid ColumnDefinitions="*"
|
||||||
RowDefinitions="Auto, 2*, Auto, Auto, *">
|
RowDefinitions="Auto, 2*, Auto, Auto, *">
|
||||||
<Button Command="{Binding ShowSettings}"
|
<Button Command="{Binding ShowSettings}"
|
||||||
@@ -136,10 +139,16 @@
|
|||||||
Width="125">
|
Width="125">
|
||||||
<DataGridTemplateColumn.CellTemplate>
|
<DataGridTemplateColumn.CellTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<Label Content="{Binding ReceiptDate}"
|
<Label VerticalAlignment="Center"
|
||||||
VerticalAlignment="Center"
|
|
||||||
Margin="8,0,8,0"
|
Margin="8,0,8,0"
|
||||||
HorizontalAlignment="Left"/>
|
HorizontalAlignment="Left">
|
||||||
|
<Label.Content>
|
||||||
|
<MultiBinding Converter="{StaticResource DateFormatter}">
|
||||||
|
<Binding Path="ReceiptDate" />
|
||||||
|
<Binding Path="$parent[UserControl].((vm:MainViewModel)DataContext).DataGridDateFormat" />
|
||||||
|
</MultiBinding>
|
||||||
|
</Label.Content>
|
||||||
|
</Label>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</DataGridTemplateColumn.CellTemplate>
|
</DataGridTemplateColumn.CellTemplate>
|
||||||
<DataGridTemplateColumn.CellEditingTemplate>
|
<DataGridTemplateColumn.CellEditingTemplate>
|
||||||
|
|||||||
Reference in New Issue
Block a user