DayButtonStyleSelector not working

2 posts, 0 answers
  1. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 16 Oct 2012 Link to this post

    Hi,

    I messed around a lot with the Calendar but I can't get it working with DayButtonStyleSelector.

    I created a new project, added a StyleSelector class and tried to use it -- SelectStyle is never called.
    My XAML:
    <Window x:Class="WpfApplication1.MainWindow"
            xmlns:VMs="clr-namespace:WpfApplication1"
            xmlns:calendar="clr-namespace:Telerik.Windows.Controls.Calendar;assembly=Telerik.Windows.Controls.Input"
            Title="MainWindow" Height="350" Width="525" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">
        <Grid>
            <Grid.Resources>
                <VMs:MyStyleSelector x:Key="stsWeekend">
                    <VMs:MyStyleSelector.SpecialStyle>
                        <Style TargetType="{x:Type calendar:CalendarButton}">
                            <Setter Property="Background">
                                <Setter.Value>
                                    <SolidColorBrush Color="Orange" Opacity="0.6"/>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </VMs:MyStyleSelector.SpecialStyle>
                </VMs:MyStyleSelector>
            </Grid.Resources>
     
            <telerik:RadCalendar HorizontalAlignment="Left" Margin="68,96,0,0" Name="radCalendar1" VerticalAlignment="Top" DayButtonStyleSelector="{StaticResource stsWeekend}"/>
        </Grid>
    </Window>

    My Style selector Class:
    namespace WpfApplication1 {
        public class MyStyleSelector : System.Windows.Controls.StyleSelector {
            public override Style SelectStyle(object item, DependencyObject container) {
                CalendarButtonContent content = item as CalendarButtonContent;
                if(content != null) {
                    if(content.Date.DayOfWeek == DayOfWeek.Tuesday && content.ButtonType == CalendarButtonType.Date) {
                        return SpecialStyle;
                    }
                }
                return base.SelectStyle(item, container);
            }
            public Style SpecialStyle { get; set; }
        }
    }

    I use 2012.2.1015.40

    Manfred
  2. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 19 Oct 2012 Link to this post

    Hello Manfred,

    You should also add DayButtonStyle="{x:Null}" to the Calendar definition in order to apply the Selector correctly:

    <telerik:RadCalendar HorizontalAlignment="Left" Margin="68,96,0,0"
                            Name="radCalendar1" VerticalAlignment="Top"
                            DayButtonStyle="{x:Null}"
                            DayButtonStyleSelector="{StaticResource stsWeekend}"/>


    Regards,
    Yana
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top