在wpf datagrid中编辑日期时,如何更改日期格式
每当我更改WPF DataGrid中的日期时,它都会尝试将我的输入转换为MM-DD-yyyy。
XAML
<Grid>
<DataGrid x:Name="datagrid" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn x:Name="DGC_CreatedTime" Header="Created" Binding="{Binding CreatedTime, StringFormat=dd/MM/yyyy}"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
以正确的格式显示数据时,DD/mm/yyyy,但是当它尝试更改为04/08/2022之类的内容时,它将其显示为08/04/2022。
而且,如果我输入25/08/2022,则不接受日期,因为没有第25个月。
我已经检查了语言 /区域设置,可以确认它们的格式正确。 我也尝试添加... system.threading.thread.currentthread.currentculture = new CultureInfo(“ en-nz”);
我可以添加CellEditEding事件并将输入的值更改为正确的格式,但是似乎应该有一个更简单的方法。
Whenever I change a date in my WPF datagrid, it try's to convert my input to MM-dd-yyyy.
XAML
<Grid>
<DataGrid x:Name="datagrid" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn x:Name="DGC_CreatedTime" Header="Created" Binding="{Binding CreatedTime, StringFormat=dd/MM/yyyy}"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
When the data is displayed in is in the correct format, dd/MM/yyyy, however when it try to change to something like 04/08/2022 then it displays it as 08/04/2022.
And if I type in 25/08/2022, then it does not accept the date, as there is no 25th month.
I have checked the language / region settings and can confirm they are in the right format.
I have also tried adding...System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-NZ");
I can add the CellEditEnding event and change the entered value to the correct format, but it seems there should be a much simpler way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试设置绑定的
convertrultur
属性:Try to set the
ConverterCulture
property of the binding: