nucleons
nucleons

Reputation: 742

DatePicker Not Displaying Date

I am working on a application in which datepicker and textbox are in the same row. Based on the types change, I am collapsing the textbox and showing datepicker. The problem is when I make datepicker visible and the user selects the date, the date is not visible in the datepicker. The code I am using is

<StackPanel Orientation="Horizontal" Name="StackPanel3">
      <Grid>
        <toolkit:DatePicker x:Name="DatePicker" Visibility="Collapsed"FontSize="32"  Width="405" Value="{Binding  RecordItem,Converter={StaticResource  RecordAndTypeFieldValueConverter},ConverterParameter=RE2, Mode=TwoWay}" ValueStringFormat="{}{0:d}"/>
        <TextBox Name="TextBox"  TextWrapping="Wrap" Text="{Binding RecordItem,Converter={StaticResource RecordAndTypeFieldValueConverter},ConverterParameter=RE2, Mode=TwoWay}" TextAlignment="Left" FontSize="32"  Width="405" />
     </Grid>
 <Image  x:Name="i2" HorizontalAlignment="Left" Height="54" Margin="0,8,0,0" VerticalAlignment="Top" Width="59" Source="/Icons/play.png" MouseLeftButtonUp="FieldTools_Click"/>
</StackPanel>

In converter I am returning the string value to datepicker's value.

Upvotes: 0

Views: 958

Answers (2)

Tigran
Tigran

Reputation: 62246

I'm not an expert in Windows Phone development, so just guessing. Usually that happens when the value of the control is not valid. Are you sure that DateTimePicker accepts string type value? To me, it should be DateTime type. If even yes, are you sure the format of the data is correct. ?

Upvotes: 0

Sam
Sam

Reputation: 986

You need to convert your textbox.text (string) value to DateTime value

For example, if you are using ddMMyy format (21JAN12), you would do this:

using System.Globalization;


     string date = TextBox1.Text.Trim().ToUpper();
                Date Time myDate= DateTime.ParseExact(date, "ddMMMyy", CultureInfo.InvariantCulture);
                DatePicker1.Value = myDate;

Or you can specify any other format you would prefer for the date.

I changed the above code for TextBox1 and DatePicker1 as it is not a good idea to name these things by the control name.

Upvotes: 1

Related Questions