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>
开发者_JAVA技巧 </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!
controls:DatePicker Text="{Binding PE_START_DATE, Mode=TwoWay, StringFormat='d'}"
You only have to add to the binding a StringFormat='MM/dd/yyyy' attribute.
<TextBox IsReadOnly="True" TextAlignment="Center" Text="{Binding AlbumDate, StringFormat='MM/dd/yyyy'}" />
精彩评论