A problem about DayTemplateSelector with set CalendarButtonStyle

5 posts, 0 answers
  1. YiChen
    YiChen avatar
    3 posts
    Member since:
    Sep 2011

    Posted 15 Sep 2011 Link to this post

    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.


  2. Pana
    Admin
    Pana avatar
    748 posts

    Posted 20 Sep 2011 Link to this post

    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 >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. YiChen
    YiChen avatar
    3 posts
    Member since:
    Sep 2011

    Posted 20 Sep 2011 Link to this post

    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.
  5. Pana
    Admin
    Pana avatar
    748 posts

    Posted 21 Sep 2011 Link to this post

    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 >>
  6. YiChen
    YiChen avatar
    3 posts
    Member since:
    Sep 2011

    Posted 22 Sep 2011 Link to this post

    Cool. It works. Thanks.
    It seems expression blender cannot rewrite all the code for us.
Back to Top
UI for WPF is Visual Studio 2017 Ready