I have two properties I'm setting for two WPF combo boxes: one for Month and one for Day. The MonthIndex
property looks like this:
private int monthIndex = DateTime.Today.Month - 1;
public int MonthIndex
{
get { return monthIndex; }
set
{
if (monthIndex != value)
{
monthIndex = value;
RaisePropertyChanged("MonthIndex");
}
}
}
I need to set the DayIndex property but unlike the Month property, it requires calculation - can't use simple declaration like
private int _dayIndex = DateTime.Today.Day - 1;
Each calendar day can have 0 or more events. e.g., if 6/30 had three events, such events would be stored as 30, 30.1, and 30.2 (in ObservableCollection DaysList and corresponding index for each event).
Below is the XAML, declaration, and method for DayIndex:
View:
<ComboBox Name="cboDay"
ItemsSource="{Binding DaysList, Mode=OneTime}"
DisplayMemberPath="fltDay"
SelectedIndex="{Binding DayIndex, Mode=TwoWay}"
IsEditable="True" />
ViewModel:
public ObservableCollection<Day> DaysList { get; set; }
private int _dayIndex;
public int DayIndex
{
get
{
// perform some calculation logic;
return _dayIndex;
}
set
{
if (_dayIndex != value)
{
_dayIndex = value;
RaisePropertyChanged("DayIndex");
}
}
}
How do I handle the declaration for dayIndex so it remains updated as the monthIndex does (so I can use its value with other code)?