【发布时间】:2019-04-24 09:13:22
【问题描述】:
我在我的项目中使用this 日历。在日历视图中,我添加了两个按钮来选择周末日期。单击按钮时,“Findes”方法在可绑定的 ObservableCollection SelectedDates 中添加日期。如果我使用这种方法在列表中添加新的日期,只在更改月份时更新。通知 OnPropertyChanged 时用户界面如何更新?
视图模型
public class CalendarioViewViewModel : MvxViewModel, INotifyPropertyChanged
{
public CalendarioViewViewModel()
{
_dates = new ObservableCollection<DateTime>();
_dates.Add(new DateTime().AddDays(5));
}
public DateTime Date
{
get => DateTime.Now;
}
private ObservableCollection<DateTime> _dates;
public ObservableCollection<DateTime> Dates
{
get { return _dates; }
set {
SetProperty(ref _dates, value);
}
}
private Command _finSemanaCommand;
public Command FinSemanaCommand =>
_finSemanaCommand ?? (_finSemanaCommand = new Command(Finde));
public void Finde()
{
Dates.Add(DateTime.Now.AddDays(7));
OnPropertyChanged("Dates");
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
var propertyChangedCallback = PropertyChanged;
propertyChangedCallback?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
Xalm 视图
<calendar:Calendar
x:Name="calendar"
MultiSelectDates="True"
SelectedBackgroundColor="Khaki"
SelectedBorderWidth="0"
BorderColor="Transparent"
StartDay="Monday"
EnableTitleMonthYearView="True"
SelectRange="False"
SelectedDates="{Binding Dates, Mode=TwoWay}"
MinDate="{Binding Date}"
TitleLabelFormat="MMM yyyy"
HorizontalOptions="Center">
【问题讨论】:
-
文件作为包作者的问题。我在代码中没有看到任何让我认为支持动态更新 SelectedDates 的内容
标签: xamarin.forms binding calendar observablecollection