私はこのシナリオをよく持っています。モデルで説明します。
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 内で、次のように、schedulemonthlyperweek モデルの各プロパティに対して毎日テンプレートを作成しました。
<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 は、別のものに変更/トグルした場合にのみ更新され、その後、予定が適切に表示されます。ユーザーが予定リストを表示する前に、別のものに切り替えてから元に戻す必要があるのは見苦しいので、自動化したいと思います。