Hi,
I'm using follwing xaml to create my column:
<sfDG:DataGridDateColumn
x:Name="C11Column"
MappingName="Grid_C11_Date"
Format="dd.MM.yyyy"
Width="100"
DisplayBinding="{Binding Grid_C11_Date, Converter={StaticResource displayBindingConverter}}">
The converter checks for a certain date and then returns null to show an empty cell. all other dates are simply returned. Thsi works absolutely fine and the cells containing the certain date are shown empty, whike others are populated.
Problem is that as soon as I use DisplayBinding, the
Format="dd.MM.yyyy"
is skipped and the datetime is fully shown including hours.
As workaround, I tried to use DateOnly as Itemsource, but this gave issues when the value was edited.
What I try to accomplish:
I have a table of many columns showing dates. If the cell contains a certain value e.g. 24.12.1985, the cell should be empty, gray and not editable.
Best regards,
Hi Tobias Horn,
To fulfill your requirement, you can format the date value directly within the
DisplayBinding converter. We have provided a basic sample for your reference,
where we removed the format type from the column and applied the format within
the DisplayBinding converter itself. Please refer to the following code snippet
and attached sample for further details.
|
<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:MauiApp1" xmlns:dataGrid="clr-namespace:Syncfusion.Maui.DataGrid;assembly=Syncfusion.Maui.DataGrid" x:Class="MauiApp1.MainPage">
<ContentPage.BindingContext> <local:OrderInfoRepository x:Name="viewModel"/> </ContentPage.BindingContext> <ContentPage.Resources> <ResourceDictionary> <local:DisplayBindingConverter x:Key="displayBindingConverter"/> </ResourceDictionary> </ContentPage.Resources>
<dataGrid:SfDataGrid x:Name="dataGrid" AutoGenerateColumnsMode="None" SelectionMode="Single" ItemsSource="{Binding OrderInfoCollection}"> <dataGrid:SfDataGrid.Columns> <dataGrid:DataGridTextColumn MappingName="OrderID" HeaderText="Order ID"/> <dataGrid:DataGridTextColumn MappingName="CustomerID" Width="110" HeaderText="Customer ID"/> <dataGrid:DataGridTextColumn MappingName="Customer" Width="140" HeaderText="Customer Name"/> <dataGrid:DataGridDateColumn MappingName="ShippedDate" Width="120" HeaderText="Shipped Date" DisplayBinding="{Binding ShippedDate, Converter={StaticResource displayBindingConverter}}"/> <dataGrid:DataGridTextColumn MappingName="ShipCity" HeaderText="City"/> <dataGrid:DataGridTextColumn MappingName="ShipCountry" HeaderText="Country"/> <dataGrid:DataGridTextColumn MappingName="Price" HeaderText="Price"/> </dataGrid:SfDataGrid.Columns> </dataGrid:SfDataGrid> </ContentPage>
In C#: namespace MauiApp1 { public partial class MainPage : ContentPage {
public MainPage() { InitializeComponent();
} }
public class DisplayBindingConverter : IValueConverter { public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value != null) { if (value is DateTime dateTime && dateTime == new DateTime(2022, 03, 22)) { return ""; } else { return ((DateTime)value).ToString("dd.MM.yyyy"); } } else { return ""; } }
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) { throw new NotImplementedException(); } }
}
|
Additionally, we want to make you aware of a known issue within the framework related to the specific format type you have used. This issue may result in improper application of the format on Windows platform, particularly in cell edit mode. We anticipate that this issue will be resolved by the framework team in the near future. For more information, you can refer to the following GitHub link:
Framework issue: 10805
Regards,
Tamilarasan