This is a migrated thread and some comments may be shown as answers.

Date filter: application culture overriding provided format string

4 Answers 333 Views
GridView
This is a migrated thread and some comments may be shown as answers.
George
Top achievements
Rank 1
George asked on 03 May 2018, 12:24 PM

I have a gridviewcolumn that is bound to a DateTime (CartridgeExpiration). I am formatting the data based on the bound Property "ExpirationDateFormat". When I set the application culture to "de-DE" and provide a DataFormatString of "MM/dd/yyyy", I see '.' as the date separator in the filter list instead of '/'. I was seeing the same behavior in the dates displayed in the gridview column until I created a CellTemplate with the MultiBinding.

Here is my GridViewColumn definition:

                <telerik:GridViewDataColumn DataMemberBinding="{Binding CartridgeExpiration}" 
                                             ShowFieldFilters = "False" 
                                            ShowFilterButton = "False"
                                            DataFormatString="{Binding ExpirationDateFormat}"
                                            HeaderCellStyle="{StaticResource SharedRadGridHeaderCellSmallFont3LineStyle}">
                                            <telerik:GridViewDataColumn.Header>
                                                <TextBlock AutomationProperties.AutomationId="QcHistoryCartridgeExpirationHeader"
                                                           Text="{x:Static AdminStrings.QcHistoryCartridgeExpirationHeader}"
                                                           TextWrapping="Wrap" TextAlignment="Center" FontSize="16"/>
                                            </telerik:GridViewDataColumn.Header>
                                            <telerik:GridViewDataColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock>
                                                        <TextBlock.Text>
                                                            <MultiBinding Converter="{StaticResource DateToStringConverter}">
                                                                <Binding Path="CartridgeExpiration"/>
                                                                <Binding RelativeSource="{RelativeSource AncestorType=UserControl}" Path="DataContext.ExpirationDateFormat"/>
                                                            </MultiBinding>
                                                        </TextBlock.Text>
                                                    </TextBlock>
                                                </DataTemplate>
                                            </telerik:GridViewDataColumn.CellTemplate>
                </telerik:GridViewDataColumn>

ExpirationDate = "MM/dd/yyyy" shows in the filter as "MM.dd.yyyy"

How can I get the filter display to use the format I have provided?

Thanks.

George

4 Answers, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 08 May 2018, 10:10 AM
Hello George,

Thank you for the provided xaml.

The result you have observed is expected since the DataFormatString property uses the string.Format method. You can observe the same result if you set the CurrentCulture to "de-DE" and try the following:
var date = DateTime.Now;
var str = date.ToString("MM/dd/yyyy");

Keeping that in mind, the approach of using a CellTemplate with a Converter is a valid way to achieve the desired requirement. 

Regards,
Vladimir Stoyanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
George
Top achievements
Rank 1
answered on 08 May 2018, 01:16 PM

Vladimir,

Thanks for the reply. In fact, I have implemented a MultiBinding Converter on the GridViewDataColumn and the data displayed on the grid is the correct format ("MM/dd/yyyy"). It's the data that shows up in the column filter that is being displayed as "MM.dd.yyyy". I have tried passing in InvariantCulture as the ConverterCulture for the DataFormatString property, but it doesn't change the filter value display.

DataFormatString="{Binding ExpirationDateFormat, ConverterCulture={x:Static globalization:CultureInfo.InvariantCulture}}"

I also tried to modify the FilteringControl ControlTemplate to provide my MultiBinding converter, but the checkbox content object is the converted string value, not the original DateTime object, so my converter will not work.

What I need is for the filter list to be displayed consistently with the grid column data, using the format string that I am binding to. Is there a way to do that?

Thanks.

George

0
Accepted
Vladimir Stoyanov
Telerik team
answered on 11 May 2018, 11:27 AM
Hello George,

Thank you for the additional information.

I believe that you can achieve your requirement by passing a ConverterCulture to the DataMemberBinding of the column. This way you would not have to declare the CellTemplate with the MultiBinding and a Converter. Here is what I have in mind:
<telerik:GridViewDataColumn DataMemberBinding="{Binding CartridgeExpiration, ConverterCulture={x:Static globalization:CultureInfo.InvariantCulture}}" DataFormatString="{Binding ExpirationDateFormat}" />

Please give this approach a try and let me know if it is suitable for your scenario.

Regards,
Vladimir Stoyanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
George
Top achievements
Rank 1
answered on 11 May 2018, 12:27 PM

Vladimir,

Thanks for the suggestion. It works great for all languages that we have!

George

Tags
GridView
Asked by
George
Top achievements
Rank 1
Answers by
Vladimir Stoyanov
Telerik team
George
Top achievements
Rank 1
Share this question
or