ConverterCulture in flexgrid net6 binding

Posted by: kisar on 5 March 2023, 9:54 pm EST

    • Post Options:
    • Link

    Posted 5 March 2023, 9:54 pm EST

    Hi

    in the previous version of the Flexgrid i used to insert

    "ConverterCulture={x:Static glob:CultureInfo.CurrentCulture}" 

    in the column binding to show properly the datetime

    I did not see how i can use in the net6 version

    Thanx

  • Posted 6 March 2023, 9:35 pm EST

    Hi,

    Thanks for reaching out to us with your query.

    Net6 Flegrid Column’s Binding property is type of String(not System.Windows.Data.Binding) where it is not possible to set ConverterCulture. However, you can achieve this requirement by setting CultureInfo.CurrentCulture for the TextBlock under a cell of particular column(DateTime column) using CellFactory.(see code snippet)

       public class CustomCellFactory : GridCellFactory
        {
            public override void BindCellContent(GridCellType cellType, GridCellRange range, FrameworkElement cellContent)
            {
                base.BindCellContent(cellType, range, cellContent);
                if (Grid.Columns[range.Column].ColumnName == "Dispatch" && cellType == GridCellType.Cell)
                {
                    if (cellContent is TextBlock tb)
                    {
                        tb.Text = (DateTime.Parse(tb.Text)).ToString(CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern, CultureInfo.CurrentCulture);
                    }
                }
            }
        }

    Please refer the attached sample for the same: GridDemo.zip

    Best Regards,

    Nitin

  • Posted 7 March 2023, 6:28 am EST

    Thank you for the explanation,

    in my opinion in this modality i need to write too much code, specially if i have different fields, date, numbers, datetime …

    It’s easier to create new formatted properties in the viewmodel.

    Personally i dont think that replace the DependencyProperty, in this new version, has been a good idea, and also im forced to adapt manually ALL flexgrid in my solution.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels