0

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!

2 Answers 2

2
controls:DatePicker Text="{Binding PE_START_DATE, Mode=TwoWay, StringFormat='d'}"
Sign up to request clarification or add additional context in comments.

Comments

1

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'}" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.