Special slots does not work

1 posts, 0 answers
  1. Mario
    Mario avatar
    8 posts
    Member since:
    Sep 2011

    Posted 15 Nov 2011 Link to this post

    Hello all,

    My special slots doesn't work. I followed your demo and I have:

    public RadScheduleViewControl()
            {
                InitializeComponent();
      
                xScheduleView.Loaded += new RoutedEventHandler(xScheduleView_Loaded);
      
                this.workingHours = new ObservableCollection<Slot>();
                this.readOnlySlots = new ObservableCollection<Slot>();
                this.UpdateWorkingHours();
                this.UpdateReadOnlySlots();
                this.specialSlots = new ObservableCollection<Slot>(this.workingHours);
                this.specialSlots.AddRange(this.readOnlySlots);
      
            }
    public ObservableCollection<Slot> SpecialSlots
           {
               get
               {
                   return this.specialSlots;
               }
               set
               {
                   this.specialSlots = value;
               }
           }
           private void UpdateWorkingHours()
           {
                
               this.workingHours.Clear();
               DateTime start = new DateTime(DateTime.Today.Year, 1, 1, 8, 0, 0);
               DateTime end = new DateTime(DateTime.Today.Year, 1, 1, 18, 0, 0);
               // Setting recurrence slot for non working hours
               // Week days
               this.workingHours.Add(new NonWorkingSlot(end, start.AddDays(1))
               {
                   RecurrencePattern = new RecurrencePattern(
                               null, RecurrenceDays.Monday | RecurrenceDays.Tuesday | RecurrenceDays.Wednesday | RecurrenceDays.Thursday, RecurrenceFrequency.Weekly, 1, null, null)
               });
               this.workingHours.Add(
                   new NonWorkingSlot(end, start.AddDays(3))
                   {
                       RecurrencePattern = new RecurrencePattern(
                                   null, RecurrenceDays.Friday, RecurrenceFrequency.Weekly, 1, null, null)
                   }); 
           }
             
           private void UpdateReadOnlySlots()
           {
               this.readOnlySlots.Clear();
               Slot readOnlyslot = new Slot() 
               
                   Start = DateTime.MinValue, 
                   End = DateTime.MaxValue, 
                   IsReadOnly = false                 
               };
               
               this.readOnlySlots.Add(readOnlyslot);
           }

    In my xsml:

    <UserControl x:Class="LightSwitchApplication.RadScheduleViewControl"
        xmlns:telerikQuickStart="clr-namespace:Telerik.Windows.Controls.QuickStart;assembly=Telerik.Windows.Controls"
        xmlns:qsf="clr-namespace:Telerik.Windows.Controls.QuickStart;assembly=Telerik.Windows.Controls"  
                 xmlns:scheduleView="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.ScheduleView"
        mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="400"
        xmlns:localCS="clr-namespace:LightSwitchApplication"
        xmlns:SpecialSlots="clr-namespace:LightSwitchApplication.UserCode.SpecialSlots">
        <!--xmlns:telerikQuickStart="clr-namespace:Telerik.Windows.Controls.QuickStart;assembly=Telerik.Windows.Controls">-->
        <!--xmlns:local="clr-namespace:Telerik.Windows.Examples.ScheduleView.Grouping.Basics"-->
      
          
        <telerikQuickStart:QuickStart.ExampleHeader>
            <TextBlock Text="Grelha de Marcações" Margin="8" />
        </telerikQuickStart:QuickStart.ExampleHeader>
      
          
        <UserControl.Resources>
            <telerik:MetroColors x:Key="MetroColors"/>
            <telerik:MetroTheme x:Key="Theme1" />
      
            <SolidColorBrush x:Key="AccentBrush" Color="{Binding Source={StaticResource MetroColors}, Path=Palette.AccentColor}" />
            <SolidColorBrush x:Key="BasicBrush" Color="{Binding Source={StaticResource MetroColors}, Path=Palette.BasicColor}" />
            <SolidColorBrush x:Key="StrongBrush" Color="{Binding Source={StaticResource MetroColors}, Path=Palette.StrongColor}" />
            <SolidColorBrush x:Key="MainBrush" Color="{Binding Source={StaticResource MetroColors}, Path=Palette.MainColor}" />
            <SolidColorBrush x:Key="MarkerBrush" Color="{Binding Source={StaticResource MetroColors}, Path=Palette.MarkerColor}" />
            <SolidColorBrush x:Key="ValidationBrush" Color="{Binding Source={StaticResource MetroColors}, Path=Palette.ValidationColor}" />
      
            <Style x:Key="Header" TargetType="qsf:HeaderedContentControl">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="qsf:HeaderedContentControl">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="30" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>
                                <Border Background="{StaticResource AccentBrush}">
                                    <ContentControl FontWeight="Bold" Foreground="{StaticResource MainBrush}" Margin="8 0 0 0" VerticalAlignment="Center" 
                                                    Content="{TemplateBinding Header}" ContentTemplate="{TemplateBinding HeaderTemplate}" />
                                </Border>
                                <Border Grid.Row="1" BorderThickness="1 0 1 1" BorderBrush="{StaticResource BasicBrush}" Background="{StaticResource MainBrush}">
                                    <ContentPresenter Margin="{TemplateBinding Padding}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" />
                                </Border>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
      
            <LinearGradientBrush x:Key="LeftColumnBackground" EndPoint="0.5,1" MappingMode="RelativeToBoundingBox"
                    StartPoint="0.5,0">
                <GradientStop Color="#FF4B4B4B" Offset="1" />
                <GradientStop Color="#FF6E6E6E" />
            </LinearGradientBrush>
              
              
            <!--Special slots: read only-->
            <LinearGradientBrush x:Key="ReadOnlyBrush" MappingMode="Absolute" SpreadMethod="Repeat" StartPoint="0,0" EndPoint="1,1">
                <LinearGradientBrush.Transform>
                    <ScaleTransform ScaleX="3" ScaleY="3" />
                </LinearGradientBrush.Transform>
                <GradientStop Offset="0.15" Color="#FF4040C2" />
                <GradientStop Offset="0.15" Color="Black" />
            </LinearGradientBrush>
      
            <SpecialSlots:SpecialSlotStyleSelector x:Key="SpecialSlotStyleSelector">
                <SpecialSlots:SpecialSlotStyleSelector.NonWorkingHourStyle>
                    <Style TargetType="telerik:HighlightItem">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate>
                                    <!--<Border Background="#4DCDCDCD"/>-->
                                    <Border Background="Black" Opacity="0.2" />
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </SpecialSlots:SpecialSlotStyleSelector.NonWorkingHourStyle>
                <SpecialSlots:SpecialSlotStyleSelector.MonthViewStyle>
                    <Style TargetType="telerik:HighlightItem">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate>
                                    <Border Background="Black" Opacity="0.2" />
                                    <!--<Border Background="Transparent" Opacity="0.4" />-->
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </SpecialSlots:SpecialSlotStyleSelector.MonthViewStyle>
                <SpecialSlots:SpecialSlotStyleSelector.ReadOnlyStyle>
                    <Style TargetType="telerik:HighlightItem">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate>
                                    <Border Background="Black" Opacity="0.2" />
                                    <!--<Rectangle Opacity="0.33" Fill="{StaticResource ReadOnlyBrush}" />-->
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </SpecialSlots:SpecialSlotStyleSelector.ReadOnlyStyle>
            </SpecialSlots:SpecialSlotStyleSelector>
      
        </UserControl.Resources>
      
      
        <Grid x:Name="LayoutRoot" Background="White" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="180" />
                <ColumnDefinition Width="2" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
      
            <telerik:RadScheduleView  x:Name="xScheduleView" 
                                      ShowDialog="xScheduleView_ShowDialog" 
                                      AppointmentSaving="xScheduleView_AppointmentSaving"
                                     AppointmentCreated="xScheduleView_AppointmentCreated"
                                     AppointmentDeleted="xScheduleView_AppointmentDeleted" 
                                     AppointmentEdited="xScheduleView_AppointmentEdited"  
                                      AppointmentCreating="xScheduleView_AppointmentCreating"                                 
                                      SpecialSlotStyleSelector="{StaticResource SpecialSlotStyleSelector}" 
                                      SpecialSlotsSource="{Binding SpecialSlots}"  
                                        Margin="2" Grid.Column="2"                            
                                        VerticalAlignment="Top"
                                      EditAppointmentDialogStyle="{StaticResource EditAppointmentDialogStyle}">
                <!--<telerik:RadScheduleView.SchedulerDialogHostFactory>
                    <localCS:SchedulerWindowFactory />
                </telerik:RadScheduleView.SchedulerDialogHostFactory>-->
                <!--SpecialSlotStyleSelector="{StaticResource CustomSpecialSlotStyleSelector}"-->
      
      
      
                <telerik:RadScheduleView.ViewDefinitions>
                    <telerik:DayViewDefinition  FirstDayOfWeek="Sunday" 
                                               DayStartTime="07:00" 
                                               DayEndTime="20:00" MajorTickLength="30min"
                                               CalendarWeekRule="FirstFourDayWeek" VisibleDays="5" />
                    <telerik:WeekViewDefinition FirstDayOfWeek="Sunday" 
                                               DayStartTime="07:00" 
                                               DayEndTime="20:00" MajorTickLength="30min"
                                               CalendarWeekRule="FirstFourDayWeek" />
                    <telerik:MonthViewDefinition FirstDayOfWeek="Sunday" 
                                                 DayStartTime="07:00" 
                                               DayEndTime="20:00" 
                                               CalendarWeekRule="FirstFourDayWeek"/>
                    <telerik:TimelineViewDefinition FirstDayOfWeek="Sunday" 
                                                 DayStartTime="07:00" 
                                               DayEndTime="20:00" 
                                               CalendarWeekRule="FirstFourDayWeek" Orientation="Vertical" />
                      
                </telerik:RadScheduleView.ViewDefinitions>
      
                  
            </telerik:RadScheduleView>
            <Border Grid.Column="2" Margin="2 37 2 2" BorderBrush="#FFC8C6C6" BorderThickness="1 0 1 1" Grid.Row="1" />
      
        </Grid>
    </UserControl>


    In the class:

    public class SpecialSlotStyleSelector : ScheduleViewStyleSelector
        {
      
            private Style nonworkingHourStyle;
            private Style monthViewStyle;
            private Style readOnlyStyle;
      
            public Style NonWorkingHourStyle
            {
                get
                {
                    return this.nonworkingHourStyle;
                }
                set
                {
                    this.nonworkingHourStyle = value;
                }
            }
      
            public Style MonthViewStyle
            {
                get
                {
                    return this.monthViewStyle;
                }
                set
                {
                    this.monthViewStyle = value;
                }
            }
      
            public Style ReadOnlyStyle
            {
                get
                {
                    return this.readOnlyStyle;
                }
                set
                {
                    this.readOnlyStyle = value;
                }
            }
      
            public override Style SelectStyle(object item, DependencyObject container, ViewDefinitionBase activeViewDefinition)
            {
                Slot slot = item as Slot;
                if (slot.IsReadOnly)
                {
                    return this.ReadOnlyStyle;
                }
                if (activeViewDefinition is MonthViewDefinition)
                {
                    return this.MonthViewStyle;
                }
                else
                {
                    if (item is NonWorkingSlot)
                    {
                        return this.NonWorkingHourStyle;
                    }
                }
                return base.SelectStyle(item, container, activeViewDefinition);
            }
        }


    and :

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Telerik.Windows.Controls;
    using Telerik.Windows.Controls.ScheduleView;
      
    namespace LightSwitchApplication.UserCode.SpecialSlots
    {
        public class NonWorkingSlot : Slot
        {
            public NonWorkingSlot(DateTime start, DateTime end)
                : base(start, end)
            {
                this.IsReadOnly = true;
                //this.Resources.Add(new Resource("Serviços", "Local"));
                  
            }
      
            public override Slot Copy()
            {
                Slot slot = new NonWorkingSlot(this.Start, this.End);
                slot.CopyFrom(this);
                return slot;
            }
        }
    }


    The only thing that I changed was the resources.
    what could be wrong?


    Thanks
Back to Top