настраиваемый стиль календаря и содержание wpf - PullRequest
0 голосов
/ 02 декабря 2018

привет, я создал стиль для своего календаря. Это словарь ресурсов:

<ResourceDictionary>
<Style TargetType="CalendarItem">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="CalendarItem">

                    <Grid x:Name="PART_Root">
                                    <Grid
                                        Name="PART_DAYS"

                                        Visibility="Visible">
                                        <Label
                                            Grid.Row="0"
                                            Grid.Column="0"
                                            Content="{Binding DaysOfWeekNames[0]}"
                                            Style="{StaticResource BaseStyle}" />
                                        <Label
                                            Grid.Row="0"
                                            Grid.Column="1"
                                            Content="{Binding DaysOfWeekNames[1]}"
                                            Style="{StaticResource BaseStyle}" />
                                        <Label
                                            Grid.Row="0"
                                            Grid.Column="2"
                                            Content="{Binding DaysOfWeekNames[2]}"
                                            Style="{StaticResource BaseStyle}" />
                                        <Label
                                            Grid.Row="0"
                                            Grid.Column="3"
                                            Content="{Binding DaysOfWeekNames[3]}"
                                            Style="{StaticResource BaseStyle}" />
                                        <Label
                                            Grid.Row="0"
                                            Grid.Column="4"
                                            Content="{Binding DaysOfWeekNames[4]}"
                                            Style="{StaticResource BaseStyle}" />
                                        <Label
                                            Grid.Row="0"
                                            Grid.Column="5"
                                            Content="{Binding DaysOfWeekNames[5]}"
                                            Style="{StaticResource BaseStyle}" />
                                        <Label
                                            Grid.Row="0"
                                            Grid.Column="6"
                                            Content="{Binding DaysOfWeekNames[6]}"
                                            Style="{StaticResource BaseStyle}" />

                                        <CalendarDayButton
                                            Grid.Row="1"
                                            Grid.Column="0"
                                            Content="{Binding Days[0]}"
                                            Style="{DynamicResource CalendarDayButtonStyle}" />
                                        <CalendarDayButton
                                            Grid.Row="1"
                                            Grid.Column="1"
                                            Content="{Binding Days[1]}"
                                            Style="{DynamicResource CalendarDayButtonStyle}" />
                                        <CalendarDayButton
                                            Grid.Row="1"
                                            Grid.Column="2"
                                            Content="{Binding Days[2]}"
                                            Style="{DynamicResource CalendarDayButtonStyle}" />
                                        <CalendarDayButton
                                            Grid.Row="1"
                                            Grid.Column="3"
                                            Content="{Binding Days[3]}"
                                            Style="{DynamicResource CalendarDayButtonStyle}" />
                                        <CalendarDayButton
                                            Grid.Row="1"
                                            Grid.Column="4"
                                            Content="{Binding Days[4]}"
                                            Style="{DynamicResource CalendarDayButtonStyle}" />
                                        <CalendarDayButton
                                            Grid.Row="1"
                                            Grid.Column="5"
                                            Content="{Binding Days[5]}"
                                            Style="{DynamicResource CalendarDayButtonStyle}" />

                                    </Grid>
                                </Grid>                                            
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

пока все не будет в порядке и будет работать нормально И это результат enter image description here

теперь я хочу заполнить названия дней и недель, поэтому я использовал привязку

Content = "{Binding Days [5]}"

и

Content = "{Binding DaysOfWeekNames [0]}"

проблема здесь!
Где мне нужно писать коды привязки?
Как следуетЯ подключаю этот resourceDictionary к CodeBehind?
Стиль завершен.Я просто не знаю, где писать коды, которые генерируют названия дней и недель.

1 Ответ

0 голосов
/ 03 декабря 2018

Вы можете объявить массивы в xaml и получить к ним доступ с помощью ключа ресурса.Текущий запрос реализации, что массивы определены в контексте данных вашего календаря

...