This is a migrated thread and some comments may be shown as answers.

A problem about DayTemplateSelector with set CalendarButtonStyle

4 Answers 123 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
YiChen
Top achievements
Rank 1
YiChen asked on 15 Sep 2011, 09:02 AM
I got a trouble about if I re-Template the CalendarButton, then the RadCalendar doesn't work with DayTemplateSelector. 

It doesnot work if I set the DayButtonStyle which inside the style I retemplate the Calendarbutton.
<telerik:RadCalendar DayButtonStyle="{StaticResource CalendarButtonStyle}" >
               <telerik:RadCalendar.Style>
                   <Style TargetType="{x:Type telerik:RadCalendar}">
                       <Setter Property="DayTemplate" Value="{x:Null}"/>
                       <Setter Property="DayTemplateSelector" >
                           <Setter.Value>
                               <local:CustomTemplateSelector/>
                           </Setter.Value>
                       </Setter>
                   </Style>
               </telerik:RadCalendar.Style>
</telerik:RadCalendar>

It will work with selector only if I delete the retemplate part in the CalendarButtonStyle.

How can I use the selector as well as retemplate the CalendarButton.

Hoping for your help. Thanks.


4 Answers, 1 is accepted

Sort by
0
Pana
Telerik team
answered on 20 Sep 2011, 01:03 PM
Hi Yichen,

Could you post your CalendarButtonStyle? I want to check what is set within that style.

All the best,
Pana
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
YiChen
Top achievements
Rank 1
answered on 21 Sep 2011, 02:10 AM
Hi Pana,

Thanks for your reply. It's very simple style. I just got it from Expression Blend 4 by using Edit template(a copy). I have changed nothing for this style. But it still cannot work.
<Style x:Key="CalendarButtonStyle" TargetType="{x:Type Telerik_Windows_Controls_Calendar:CalendarButton}">
            <Setter Property="Padding" Value="0"/>
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Telerik_Windows_Controls_Calendar:CalendarButton}">
                        <Grid x:Name="LayoutRoot" Background="Transparent">
                            <Border BorderBrush="{TemplateBinding BorderThickness}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"/>
                            <Telerik_Windows_Controls_Chromes:ButtonChrome x:Name="SelectionChrome" CornerRadius="1" Margin="2" RenderNormal="False" RenderSelected="{TemplateBinding IsSelected}" RenderFocused="{TemplateBinding IsFocused}" RenderHighlighted="{TemplateBinding IsMouseOver}">
                                <telerik:StyleManager.Theme>
                                    <telerik:Office_BlackTheme/>
                                </telerik:StyleManager.Theme>
                            </Telerik_Windows_Controls_Chromes:ButtonChrome>
                            <Border x:Name="TodayVisual" BorderThickness="1" CornerRadius="2" Margin="1" Visibility="Collapsed">
                                <Border.BorderBrush>
                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                        <GradientStop Color="#FF282828"/>
                                        <GradientStop Color="#FF5F5F5F" Offset="1"/>
                                    </LinearGradientBrush>
                                </Border.BorderBrush>
                            </Border>
                            <ContentPresenter x:Name="Content" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsFromCurrentView" Value="False">
                                <Setter Property="Opacity" TargetName="Content" Value="0.5"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="Opacity" TargetName="LayoutRoot" Value="0.5"/>
                            </Trigger>
                            <Trigger Property="ButtonType" Value="TodayDate">
                                <Setter Property="Visibility" TargetName="TodayVisual" Value="Visible"/>
                            </Trigger>
                            <Trigger Property="ButtonType" Value="WeekNumber">
                                <Setter Property="Visibility" TargetName="SelectionChrome" Value="Collapsed"/>
                            </Trigger>
                            <Trigger Property="ButtonType" Value="WeekName">
                                <Setter Property="Visibility" TargetName="SelectionChrome" Value="Collapsed"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

The key point is not this style, but the template inside. If I remove the template property inside this style, it will works with DayTemplateSelector.

Hoping for your reply.
0
Pana
Telerik team
answered on 21 Sep 2011, 06:43 AM
Hi,

I am not sure why this would not work. In general the ContentControl inside the ControlTemplate for WPF should have:

ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"

if I am not mistaken. Could you try adding that line and test the selector again?

Regards,
Pana
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
YiChen
Top achievements
Rank 1
answered on 22 Sep 2011, 08:39 AM
Cool. It works. Thanks.
It seems expression blender cannot rewrite all the code for us.
Tags
Calendar
Asked by
YiChen
Top achievements
Rank 1
Answers by
Pana
Telerik team
YiChen
Top achievements
Rank 1
Share this question
or