I have alarm model objects that have a Repeat collection containing days on which the alarm should be repeated. I want to display alarms in the form of a grid, grouped on the day of the week (for example, Monday, Tuesday, etc.).
And I add all these alarms to the "Alarms" collection
For each alarm in the alarms, I again create alarms for each day in the re-collection of the alarm and add them all to the TotalAlarms collection.
foreach (Alarm alarm in this.Config.Alarms) { foreach (DayOfWeek day in alarm.Repeat) { this.tempAlarm = this.CopyAlarm(alarm); tempAlarm.DayOfWeek = day; TotalAlarms.Add(tempAlarm); } }
And I use linq to group by the DayOfWeek property of the alarm model, which indicates the day on which the alarm should go out.
var result = from t in _ViewModel.TotalAlarms group t by t.DayOfWeek into q orderby q.Key select q;
And add this result to groupedItemsViewSource (binding to grid data source)
groupedItemsViewSource.Source = result;
and for the grid title, binding it to the "key"
<TextBlock Text="{Binding Key}" Style="{StaticResource TitleTextStyle}" FontSize="20" HorizontalAlignment="Stretch" VerticalAlignment="Center" Width="100" Height="30" Margin="5"/>
This approach displays only the days of the week for which there is an alarm. For example, if the alarm is set on Friday and Saturday, only Friday and Saturday are displayed in group headings.
What I want is all the fates that are shown as group headlines, and if there are no worries on that day, then it can be empty. But group headings should be displayed all days.
It's really hard for me to think about how to do this. If anyone has any ideas please help me here.
thanks