我有这个场景很好,我会让模型解释。
public class ScheduleMonthlyPerDayModel
{
public DateTime Date { get; set; }
public string Day
{
get
{
return Date.Day.ToString();
}
}
ObservableCollection<AppointmentDTO> _appointments;
public ObservableCollection<AppointmentDTO> Appointments
{
get
{
return _appointments;
}
set
{
_appointments = value;
if (value.Count > 0)
NotifyOfPropertyChange(() => HasSchedule);
}
}
public bool BelongsToCurrentMonth
{
get;
set;
}
public bool HasSchedule
{
get
{
return _appointments.Count > 0 ? true : false;
}
}
public ScheduleMonthlyPerDayModel()
{
_appointments = new ObservableCollection<AppointmentDTO>();
}
public void ClearCollection()
{
_appointments.Clear();
}
}
public class ScheduleMonthlyPerWeekModel
{
public ScheduleMonthlyPerDayModel Sunday{get; set;}
public ScheduleMonthlyPerDayModel Monday{get; set;}
public ScheduleMonthlyPerDayModel Tuesday{get; set;}
public ScheduleMonthlyPerDayModel Wednesday{get; set;}
public ScheduleMonthlyPerDayModel Thursday{get; set;}
public ScheduleMonthlyPerDayModel Friday{get; set;}
public ScheduleMonthlyPerDayModel Saturday{get; set;}
}
与 xaml 的绑定正在使用 xaml 的一瞥,如下所示:
headereditemscontrol itemsSource= weekcollection
,其中 weekcollection 是 的对象schedulemonthlyperweekmodel
。
在该 headereditemscontrol 中,我每天都为 schedulemonthlyperweekmodel 的每个属性进行模板化,如下所示:
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Style="{StaticResource CalendarDates}" Text="{Binding Path=Saturday.Day}" />
<ListBox Grid.Row="1" Grid.ColumnSpan="2" Padding="0"
ItemsSource="{Binding Path= Saturday.Appointments}"
ItemTemplate="{StaticResource myItemStyle}"
Visibility="{Binding Path=Saturday.HasSchedule, Converter={StaticResource BoolToVisibilityConverter}}" />
基本上,我试图通过每天都有一系列约会来实现每月视图。我的问题是,当我以编程方式将项目添加到例如此处的 saturday.appointments 集合时,通过调试附加项目成功并通知主集合(weekcollection),不会刷新 UI。
我想要实现的是:在我将假定的约会添加到其相应的日期/日期后,用户界面也会相应地更新,但我该怎么做呢?
目前,UI 仅在我更改/切换到不同然后返回时才会更新,之后会很好地显示约会。我想自动化它,因为要求用户在看到约会列表之前切换到其他东西然后返回是很难看的。