gpt4 book ai didi

xaml - 在DatePicker更改时刷新表格

转载 作者:行者123 更新时间:2023-12-03 10:32:57 25 4
gpt4 key购买 nike

当用户使用MVVM模式更改Form时,我正在尝试刷新Date中的数据。

Xml:

<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">
....

ViewModel:
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与 View 模型中对象的“刷新”连接?

最佳答案

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();
}

我在这里查看了文档: https://msdn.microsoft.com/en-us/library/system.windows.forms.monthcalendar.dateselected(v=vs.110).aspx

您可以根据需要设置字符串的格式。

关于xaml - 在DatePicker更改时刷新表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48585977/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com