简体   繁体   中英

WP7 DatePicker, TimePicker data binding

I'm building an application that needs to display and accept dates from my model ( which is retrieved from a database). The model exposes a property called EntryTime:

 private DateTime entryTime;

[Column]
public DateTime EntryTime
{
    get { return entryTime;  }
    set
    {
        if (entryTime != value)
        {
            this.NotifyPropertyChanging("EntryTime");
            entryTime = value;
            this.NotifyPropertyChanged("EntryTime");
        }
    }
}

I have both a DatePicker and a TimePicker on my page and want to bind them both to the EntryTime. I tried binding them just by binding the values but that didn't work:

    <toolkit:DatePicker HorizontalAlignment="Left" Margin="151,6,0,0" x:Name="dateCurrent" VerticalAlignment="Top" Width="175" Value="{Binding CurrentEntry.EntryDate}" />
    <toolkit:TimePicker HorizontalAlignment="Left" Margin="313,6,0,0" Name="timeCurrent" VerticalAlignment="Top" Value="{Binding CurrentEntry.EntryDate}" Width="137" />

I'm relatively new to Silverlight so i'm not sure what i can do to just bind the time picker to the time for EntryDate and the DatePicker to the date for EntryDate.

Thank you for your help

I had a same problem. Try to bind DatePicker to DateTime? not to DateTime

The binding should work. If you can elaborate on exactly what issue you're having that would be great. The one thing I did notice that you were missing was the "TwoWay" Mode on your binding:

    <toolkit:DatePicker HorizontalAlignment="Left" 
              Margin="151,6,0,0" 
              x:Name="dateCurrent" 
              VerticalAlignment="Top"  
              Width="175" 
              Value="{Binding CurrentEntry.EntryDate, Mode=TwoWay}" />

    <toolkit:TimePicker 
              HorizontalAlignment="Left" 
              Margin="313,6,0,0" 
              Name="timeCurrent" 
              VerticalAlignment="Top" 
              Value="{Binding CurrentEntry.EntryDate, Mode=TwoWay}" Width="137" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM