设置 Silverlight DataForm 中 DatePicker 控件中日期的格式
这让我抓狂!
我在 silverlight 中有一个 RIA 服务驱动的数据表单,其中包含一个日期选择器控件。我想以 ddMMMyyyy 格式显示日期。这是 xaml 的示例:
<dataFormToolkit:DataForm x:Name="dataForm" AutoGenerateFields="False">
<dataFormToolkit:DataForm.EditTemplate>
<DataTemplate>
<StackPanel>
<dataFormToolkit:DataField Label="First Name">
<TextBox Text="{Binding PE_FIRST_NAME, Mode=TwoWay}"/>
</dataFormToolkit:DataField>
<dataFormToolkit:DataField Label="Surname">
<TextBox Text="{Binding PE_SURNAME_NAME,Mode=TwoWay}"/>
</dataFormToolkit:DataField>
<dataFormToolkit:DataField Label="Department">
<ComboBox x:Name="cboDepartment" DisplayMemberPath="CC_NAME" SelectedValuePath="CC_ID" SelectedValue="{Binding Path=CC_ID, Mode=TwoWay}"/>
</dataFormToolkit:DataField>
<dataFormToolkit:DataField Label="Start Date">
<controls:DatePicker Text="{Binding PE_START_DATE, Mode=TwoWay}"/>
</dataFormToolkit:DataField>
</StackPanel>
</DataTemplate>
</dataFormToolkit:DataForm.EditTemplate>
</dataFormToolkit:DataForm>
</StackPanel>
我已遵循中给出的建议 如何更改 Silverlight DatePicker 控件中的日期格式? 并将以下几行添加到我的应用程序启动中:
Thread.CurrentThread.CurrentCulture = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern = "ddMMMyyyy";
但这没有任何区别,日期始终以其原始格式显示,例如 1/3/2006 12:00AM
是否有某些原因导致当前文化无法在数据形式?
更新:如果我通过不使用数据表单来以困难的方式实现相同的表单,那么日期的格式是正确的!
This is driving me nuts!
I have a RIA Services driven dataform in silverlight which contains a datepicker control. I want to display the date in ddMMMyyyy format. Here is a sample of the xaml:
<dataFormToolkit:DataForm x:Name="dataForm" AutoGenerateFields="False">
<dataFormToolkit:DataForm.EditTemplate>
<DataTemplate>
<StackPanel>
<dataFormToolkit:DataField Label="First Name">
<TextBox Text="{Binding PE_FIRST_NAME, Mode=TwoWay}"/>
</dataFormToolkit:DataField>
<dataFormToolkit:DataField Label="Surname">
<TextBox Text="{Binding PE_SURNAME_NAME,Mode=TwoWay}"/>
</dataFormToolkit:DataField>
<dataFormToolkit:DataField Label="Department">
<ComboBox x:Name="cboDepartment" DisplayMemberPath="CC_NAME" SelectedValuePath="CC_ID" SelectedValue="{Binding Path=CC_ID, Mode=TwoWay}"/>
</dataFormToolkit:DataField>
<dataFormToolkit:DataField Label="Start Date">
<controls:DatePicker Text="{Binding PE_START_DATE, Mode=TwoWay}"/>
</dataFormToolkit:DataField>
</StackPanel>
</DataTemplate>
</dataFormToolkit:DataForm.EditTemplate>
</dataFormToolkit:DataForm>
</StackPanel>
I have followed the advice given in
How to change date format in Silverlight DatePicker control?
and added the following lines to my App startup:
Thread.CurrentThread.CurrentCulture = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern = "ddMMMyyyy";
but it doesn't make any difference, the date always comes out in its raw format, e.g. 1/3/2006 12:00AM
Is there some reason why the current culture is not working in a dataform?
Update: If I implement the same form the hard way by not using a dataform then the date is in the correct format!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需向绑定添加 StringFormat='MM/dd/yyyy' 属性。
You only have to add to the binding a StringFormat='MM/dd/yyyy' attribute.