I am developing a calendar where my days are aligned like this
<Label Grid.Row="1" Grid.Column="1" Content="{Binding Path=SundayLabel, FallbackValue=Sunday}" Style="{StaticResource ResourceKey=DayLabelStyle}" />
<custom:DayDisplay Grid.Row="2" Grid.Column="1" x:Name="SundayDisplay" />
<Label Grid.Row="1" Grid.Column="2" Content="{Binding Path=MondayLabel, FallbackValue=Monday}" Style="{StaticResource ResourceKey=DayLabelStyle}" />
<custom:DayDisplay Grid.Row="2" Grid.Column="2" x:Name="MondayDisplay" />
and so forth. DayDisplay is a custom WPF control.
The control containing all theese DayDisplays needs some way to set the individual days with a DateTime preferably from code behind.
Is there some way to expose a custom property in my DayDisplay view so i could do something like:
<custom:DayDisplay Grid.Row="2" Grid.Column="2" x:Name="MondayDisplay" x:Day="{MondayDateTime}"/>
Preferably i would like to store all custom:DayDisplay pairs in a Dictionary and have them autogenerated also if it is possible. Any help is greatly appreciated 🙂
Thanks,
Niklas
you should expose a DateTime dependency property on the control, done like so:
if you want this to be auto generated, what you should do is have an ItemsControl that contains this dayControl of yours, like so:
and then DataBind it from code behind: