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

DayButtonStyleSelector not working

1 Answer 125 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
ManniAT
Top achievements
Rank 2
ManniAT asked on 16 Oct 2012, 10:30 PM
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

1 Answer, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 19 Oct 2012, 11:01 AM
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.

Tags
Calendar
Asked by
ManniAT
Top achievements
Rank 2
Answers by
Yana
Telerik team
Share this question
or