当用户使用MVVM模式更改Form
时,我尝试刷新Date
中的数据。
的Xaml:
<DatePicker DateSelected="EntryDate_Selected"
x:Name="EntryDate" Date="{Binding MoodEntry.EntryDate, Mode=TwoWay}">
<Slider x:Name="SliderSleep" Value="{Binding MoodEntry.Sleep, Mode=TwoWay}"
Minimum="0" Maximum="5">
....
视图模型:
public class RegisterViewModel : INotifyPropertyChanged
{
public MoodEntry MoodEntry { get; set; }
}
public RegisterViewModel()
{
MoodEntry = App.MoodDatabase.GetMoodEntry(DateTime.Today);
if (MoodEntry == null)
MoodEntry = new MoodEntry();
LowerLimitDate = new DateTime(2018, 1, 1);
HighLimitDate = DateTime.Today;
}
MoodEntry.cs
namespace myMood.Models
{
[Table("MoodEntries")]
public class MoodEntry
{
[PrimaryKey, AutoIncrement, Column("MoodEntryID")]
public int MoodEntryID { get; set; }
[Indexed]
public DateTime EntryDate { get; set; }
...
Register.xaml.cs:
private void EntryDate_Selected(object sender, ValueChangedEventArgs e)
{
// What goes here?
}
如何将EntryDate_Selected与&#34; refresh&#34;连接起来? viewmodel中的对象?
答案 0 :(得分:1)
private void EntryDate_Selected(object sender, DateRangeEventArgs e)
{
// Show the start and end dates in the text box.
this.EntryDate.Text = "Date Selected: Start = " +
e.Start.ToShortDateString() + " : End = " + e.End.ToShortDateString();
}
可以根据需要格式化字符串。