I'm trying to display the days of the month on a custom calendar in the right spot. Using binding and using observable collection I have a grid with 7 columns and 6 rows, I need to display the date(number) on each textBlock. I've gotten myself to a point that I'm completely lost and I don't know what else to try. Somehow I need to get the day of week and what day it is. I'm not even sure if I'm going about this the right way. I know the XAML is good(should be at least) I'm confused on using datetime and observable collections though. Any help is greatly appreciated.
Here I use Observable collection:
public SchedulePage(MainWindow parentForm)
{
InitializeComponent();
_parentForm = parentForm;
// DateTime date = new DateTime(year, month, day);
_parentForm.bindings = new BindingCamper();
int day = DateTime.DaysInMonth(2011, 10);
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 7; j++)
{
_parentForm.bindings.schedule.Add(new Schedule { WeekNo = i, WeekDay = j });
DataContext = _parentForm.bindings;
}
}
}
This is a Schedule class I have:
public class Schedule //: INotifyPropertyChanged
{
public int WeekNo { get; set; }
public int WeekDay { get; set; }
public DateTime Date { get; set; }
public int datenum
{
get { return (int)Date.DayOfWeek; }
}
}
And the XAML:
<ItemsControl ItemsSource="{Binding schedule}" Name="Calender" Margin="0,34,0,0" VerticalAlignment="Stretch">
<ItemsControl.Template>
<ControlTemplate TargetType="ItemsControl" >
<Border BorderBrush="Aqua" BorderThickness="1" CornerRadius="15">
<ItemsPresenter/>
</Border>
</ControlTemplate>
</ItemsControl.Template>
<!-- ItemsPanelTemplate -->
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid ShowGridLines="True" Name="gridCalender">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text ="{Binding datenum}" Background="#FFBCF4E0" OpacityMask="Black" Grid.Column="{Binding datenum}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
<!-- ItemContainerStyle -->
<ItemsControl.ItemContainerStyle>
<Style >
<Setter Property="Grid.Column" Value="{Binding WeekDay}" />
<Setter Property="Grid.Row" Value="{Binding WeekNo}" />
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
I also have a class creating a new ObservableCollection();