I have created a Day class:
public class Day { public int DayOfMonth { get { return dayOfMonth; } } public List<Entry> CalendarDayItems { get { return calendarDayItems; } set { calendarDayItems = value; } } private DateTime date; private int dayOfMonth; private List<Entry> calendarDayItems; public Day(DateTime date, List<Entry> entries) { this.date = date; this.dayOfMonth = date.Day; this.calendarDayItems = entries; } } Next I have created a WPF UserControl for which I want to bind the collection of days to the ItemsControl. I have created a dependency property ObservableCollection<Day> Days which is bound to the ItemsControl. Here's XAML:
<UserControl ... Name="CalendarMonthViewControl"> ... <ItemsControl ItemsSource="{Binding ElementName=CalendarMonthViewControl, Path=Days}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <UniformGrid Rows="6" Columns="7" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate DataType="Day"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition /> </Grid.ColumnDefinitions> <!-- The following two bindings don't work --> <TextBlock Grid.Column="0" Text="{Binding Path=DayOfMonth}" /> <ItemsControl Grid.Column="1" ItemsSource="{Binding Path=CalendarDayItems}"> </ItemsControl> </Grid> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> ... I have a couple of questions:
- Am I using the proper way to bind a dependecy property to the
ItemsControl, i.e. is it recommended to name the control and then to reference it as a binding source? - The main problem is that the
TextBlockand the secondItemsControlwon't bind toDayOfMonthandCalendarDayItemsproperties of theDayclass, respectively.
TextBlockand theItemsControlare not showing any data,DayOfMonthvalue and the list ofCalendarDayItemsare not showing. They are just blank, but there are no errors or exceptions.Dayitems in the collection...