RadCalendar CustomTemplate

4 posts, 0 answers
  1. Juan
    Juan avatar
    2 posts
    Member since:
    Dec 2010

    Posted 06 Jan 2011 Link to this post

    Hi,
    I'm new using these components, try to follow the example of how to create a template but the ide I get the following error message

    "The type 'my:CustomTemplateSelector' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built."

    XAML
    <controls:WindowMain xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" 
                         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                         xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
                         xmlns:my="http://schemas.telerik.com/2008/xaml/presentation"
                         xmlns:telerikGridView="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"   
                        Width="800"
                        Height="550"
                        xmlns:controls="clr-namespace:FrameworkWeb.Controls;assembly=FrameworkWeb.Controls"   
                        x:Class="FrameworkWeb.TimeOff.Vistas.Request"
                        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">
     
        <Border x:Name="LayouRoot" CornerRadius="9" Background="White">
            <Grid x:Name="Objects" >
                <TextBlock Name="Message" Text="Loading records..." VerticalAlignment="Top" HorizontalAlignment="Right" Margin="8" Foreground="Red" />
                <telerik:RadCalendar Name="radCalendarDates" VerticalAlignment="Top" HorizontalAlignment="Right" Height="196" SelectionMode="Extended" Culture="en-US" DayTemplate="{x:Null}">
                    <telerik:RadCalendar.DayTemplateSelector>
                        <!--Custom Template selector, sill actually choose just one template-->
                        <my:CustomTemplateSelector>
                            <my:CustomTemplateSelector.DefaultTemplate>
                                <!--A custom template-->
                                <DataTemplate x:Key="defaultTemplate">
                                    <TextBlock Text="{Binding Text}" />
                                </DataTemplate>
                            </my:CustomTemplateSelector.DefaultTemplate>
                        </my:CustomTemplateSelector>
                    </telerik:RadCalendar.DayTemplateSelector>
                </telerik:RadCalendar>
                <telerikGridView:RadGridView HorizontalAlignment="Stretch"
                                             Margin="0,219,0,37"
                                             Name="rgvTimeOff"
                                             VerticalAlignment="Stretch"
                                             AutoGenerateColumns="False" 
                                             RowIndicatorVisibility="Collapsed"
                                             KeyDown="rgvTimeOff_KeyDown"
                                             SelectionUnit="FullRow"
                                             RowDetailsVisibilityChanged="rgvTimeOff_RowDetailsVisibilityChanged"
                                             IsReadOnly="True"
                                             SelectionMode="Extended"
                                             RowLoaded="rgvTimeOff_RowLoaded">
                    <telerikGridView:RadGridView.Columns>
                        <telerikGridView:GridViewToggleRowDetailsColumn />
                        <telerikGridView:GridViewDataColumn Header="Id" DataMemberBinding="{Binding Id}" IsVisible="False" />
                        <telerikGridView:GridViewDataColumn Header="Request Number" DataMemberBinding="{Binding DepartmentName}" Width="*"/>
                        <telerikGridView:GridViewDataColumn Header="Date" DataMemberBinding="{Binding DepartmentName}" Width="*"/>
                        <telerikGridView:GridViewDataColumn Header="Day" DataMemberBinding="{Binding DepartmentName}" Width="*"/>
                        <telerikGridView:GridViewDataColumn Header="Licence Type" DataMemberBinding="{Binding DepartmentName}" Width="*"/>
                        <telerikGridView:GridViewDataColumn Header="Licence SubType" DataMemberBinding="{Binding DepartmentNumber}"/>
                        <telerikGridView:GridViewDataColumn Header="Request Hours" DataMemberBinding="{Binding Comments}"/>
                    </telerikGridView:RadGridView.Columns>
                </telerikGridView:RadGridView>
                <Border BorderBrush="Gray" CornerRadius="0,0,9,9" BorderThickness="0,0.5,0,0" RenderTransformOrigin="0.5,0.5" VerticalAlignment="Bottom" Height="40" Background="Black">
                    <Grid>
                        <StackPanel x:Name="ToolBarButtons" Orientation="Horizontal" ScrollViewer.HorizontalScrollBarVisibility="Disabled"/>
                        <StackPanel x:Name="ToolBarButtonsMove" Orientation="Horizontal" HorizontalAlignment="Right" ScrollViewer.HorizontalScrollBarVisibility="Disabled"/>
                    </Grid>
                </Border>
                <TextBlock Height="23" HorizontalAlignment="Left" Margin="10,10,0,0" Name="textBlock1" Text="Licence Type:" VerticalAlignment="Top" />
                <ComboBox Height="23" HorizontalAlignment="Left" Margin="120,8,0,0" Name="cmbLicenceType" VerticalAlignment="Top" Width="200" />
                <TextBlock Height="23" HorizontalAlignment="Left" Margin="10,40,0,0" Name="textBlock2" Text="Licence Sub Type:" VerticalAlignment="Top" />
                <ComboBox Height="23" HorizontalAlignment="Left" Margin="120,38,0,0" Name="cmbLicenceSubType" VerticalAlignment="Top" Width="200" />
                <TextBlock Height="23" HorizontalAlignment="Left" Margin="10,70,0,0" Text="Supervisor:" VerticalAlignment="Top" />
                <TextBox Height="23" HorizontalAlignment="Left" Margin="120,68,10,0" Name="txtSupervisor" VerticalAlignment="Top" Width="200" IsReadOnly="True" />
                <TextBlock Height="23" HorizontalAlignment="Left" Margin="10,95,0,0" Text="Balance:" VerticalAlignment="Top" />
                <TextBox Height="23" HorizontalAlignment="Left" Margin="120,92,0,0" Name="txtBalance" VerticalAlignment="Top" Width="200" IsReadOnly="True" />           
                <TextBlock Height="23" HorizontalAlignment="Left" Margin="10,117,0,0" Name="textBlock4" Text="Comments:" VerticalAlignment="Top" />
                <RichTextBox HorizontalAlignment="Left" Margin="120,117,0,0" Name="rctxtComments" VerticalAlignment="Top" Width="416" Height="101" />
            </Grid>
        </Border>
    </controls:WindowMain>

    C#
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using FrameworkWeb.Resource;
    using FrameworkWeb.Controls;
    using FrameworkWeb.Utilities;
    using System.Data.Services.Client;
    using System.ComponentModel;
    using System.Windows.Data;
    using System.ComponentModel.DataAnnotations;
    using FrameworkWeb.TimeOff.Dto;
    using Telerik.Windows.Controls.GridView;
    using Telerik.Windows.Controls;
    using Telerik.Windows.Controls.Calendar;
     
    namespace FrameworkWeb.TimeOff.Vistas
    {
        public partial class Request : WindowMain
        {
            #region Variables
            Data.DataAccess _dataAccess = new Data.DataAccess();
            List<Data.Service.Status> _statusList = new List<Data.Service.Status>();
            List<String> _statusNameList = new List<String>();
            List<JobTitleDto> _recordsList = new List<JobTitleDto>();
            Generals _utilGenerals = new Generals();
            #endregion
     
            #region Inicializaciones

            public Request()
            {
                this.InitializeComponent();
                this.InitializeToolBar();
                this.InitializeStatusList();
                this.InitializeRecordsList();
            }
     

            private void InitializeToolBar()
            {
                ToolBarButton _refreshBtn = new ToolBarButton("Imagenes/Refresh.png", "Refresh", "Refresh list");
                _refreshBtn.Click += new RoutedEventHandler(Refresh_Record);
                this.ToolBarButtons.Children.Add(_refreshBtn);
     
                ToolBarButton _newBtn = new ToolBarButton("Imagenes/New.png", "New", "New Record");
                _newBtn.Click += new RoutedEventHandler(New_Record);
                this.ToolBarButtons.Children.Add(_newBtn);
     
                ToolBarButton _deleteBtn = new ToolBarButton("Imagenes/Remove.png", "Delete", "Delete records");
                _deleteBtn.Click += new RoutedEventHandler(Delete_Record);
                this.ToolBarButtons.Children.Add(_deleteBtn);
     
                ToolBarButton _saveBtn = new ToolBarButton("Imagenes/Save.png", "Save", "Save Records");
                _saveBtn.Click += new RoutedEventHandler(Save_Record);
                this.ToolBarButtons.Children.Add(_saveBtn);
     
                ToolBarButton _printBtn = new ToolBarButton("Imagenes/Print.png", "Print", "Print List");
                _printBtn.Click += new RoutedEventHandler(Print_Record);
                this.ToolBarButtons.Children.Add(_printBtn);
            }
     
            private void InitializeStatusList()
            {
                var _query = ((DataServiceQuery<Data.Service.Status>)(from s in _dataAccess._dataContext.Status
                                                                      orderby s.Name
                                                                      select s));
     
                _query.BeginExecute(r =>
                {
                    Deployment.Current.Dispatcher.BeginInvoke(delegate()
                    {
                        // Cargar el resultado del query a una variable
                        var _items = _query.EndExecute(r).ToList();
     
                        _statusList.Clear();
                        _statusNameList.Clear();
                        foreach (var _item in _items)
                        {
                            _statusList.Add(_item);
                            _statusNameList.Add(_item.Name);
                        }
                    });
                }, null);
            }
     
            private void InitializeRecordsList()
            {
                _utilGenerals.DisplayText(this.Message, "Loading records...");
     
                var _query = ((DataServiceQuery<Data.Service.JobTitles>)(from j in _dataAccess._dataContext.JobTitles
                                                                         orderby j.Title
                                                                         select j)).Expand("Status");
     
                _query.BeginExecute(r =>
                {
                    Deployment.Current.Dispatcher.BeginInvoke(delegate()
                    {
                        var _items = _query.EndExecute(r).ToList();
     
                         _recordsList.Clear();
                        this.rgvTimeOff.ItemsSource = null;
                        foreach (var _item in _items)
                        {
                            _recordsList.Add(new JobTitleDto()
                            {
                                JobTitle = _item.Title,
                                StatusName = _item.Status.Name,
                                CreationDate = (DateTime)_item.CreationDate,
                                ModifiedDate = (DateTime)_item.ModifiedDate,
                                ID = _item.Id,
                                StatusID = _item.Status.Id,
                                JobComments = _item.Comments,
                                JobScale = (Int32)_item.Scale,
                                JobTitleRecord = _item,
                                Updated = false
                            });
                        }
     
                        // Cargar finalmente la grilla
                        this.rgvTimeOff.ItemsSource = _recordsList;
     
                        _utilGenerals.DisplayText(this.Message, String.Empty);
                    });
                }, null);
     
            }
            #endregion
     
            #region Control de los botones de la barra de herramientas       
    void
    New_Record(object sender, RoutedEventArgs e)
            {
                MessageBox.Show("Under construction", this.WindowControlBase.TitleWindows, MessageBoxButton.OK);
            }
     
            void Delete_Record(object sender, RoutedEventArgs e)
            {
                MessageBox.Show("Under construction", this.WindowControlBase.TitleWindows, MessageBoxButton.OK);
            }
     
            void Save_Record(object sender, RoutedEventArgs e)
            {
                MessageBox.Show("Under construction", this.WindowControlBase.TitleWindows, MessageBoxButton.OK);
                     
     
            }
     
            void Refresh_Record(object sender, RoutedEventArgs e)
            {
                if (this.RecordsChanged())
                {
                    if (MessageBox.Show("There are records without saving\nChanges will be lost. Continue?", this.WindowControlBase.TitleWindows, MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                        this.Refresh();
                }
                else
                    this.Refresh();
            }
     
            void Print_Record(object sender, RoutedEventArgs e)
            {

            }
            #endregion
     
            #region Funcionaidades generales
            private void Refresh()
            {
                _dataAccess = new Data.DataAccess();
                this.InitializeStatusList();
                this.InitializeRecordsList();
            }
     
            private void Save(Boolean inShowResult)
            {

            }
     
            private Boolean RecordsChanged()
            {
                Boolean _return = false;
     
                foreach (var _record in _recordsList)
                {
                    if (_record.Updated)
                    {
                        _return = true;
                        break;
                    }
                }
     
                return _return;
            }

           
    private void Delete()
            {

            }
     
            private void Insert()
            {
            }
     
            private void rgvTimeOff_KeyDown(object sender, KeyEventArgs e)
            {
                //if (e.Key == Key.Delete)
                //    this.Delete();
     
                //if (e.Key == Key.Insert)
                //    this.Insert();
            }
     
            private void rgvTimeOff_RowDetailsVisibilityChanged(object sender, GridViewRowDetailsEventArgs e)
            {
                if (e.Visibility.Value == System.Windows.Visibility.Visible)
                {
                    e.Row.IsSelected = true;
                }
            }
     
            private void rgvTimeOff_RowLoaded(object sender, RowLoadedEventArgs e)
            {

            }
     

            public override void endAsyncRequest()
            {
                for (int i = this._asyncCallBackList.Count - 1; i >= 0; i--)
                {
                    switch (this._asyncCallBackList[i].key)
                    {
                        case "Save":
                        case "Delete":
     
                            this.Refresh();
     
                            Int32 _recordsOK = Convert.ToInt32(((List<String>)this._asyncCallBackList[i].responseAsync)[0]);
                            Int32 _recordsBad = Convert.ToInt32(((List<String>)this._asyncCallBackList[i].responseAsync)[1]);
                            String _recordsErrors = ((List<String>)this._asyncCallBackList[i].responseAsync)[2];
                            String _message = String.Format("{0} records {1} OK", _recordsOK, this._asyncCallBackList[i].key == "Save" ? "Saved" : "Deleted");
                            if (_recordsBad > 0)
                                _message += String.Format("\n but {0} records with errors\nErrors: {1}", _recordsOK, _recordsErrors);
     
                            MessageBox.Show(_message, this.WindowControlBase.TitleWindows, MessageBoxButton.OK);
     
                            break;
     
                        default:
                            break;
                    }
                    this._asyncCallBackList.RemoveAt(i);
                }
            }
            #endregion
     
           
        }
     
        public class CustomTemplateSelector : DataTemplateSelector
        {
            public override DataTemplate SelectTemplate(object item, DependencyObject container)
            {
                CalendarButtonContent content = item as CalendarButtonContent;
                if (content != null)
                {
                    if (content.Date.DayOfWeek == DayOfWeek.Saturday || content.Date.DayOfWeek == DayOfWeek.Sunday)
                    {
                        content.IsEnabled = false;
                    }
                }
                return DefaultTemplate;
            }
            public DataTemplate DefaultTemplate
            {
                get;
                set;
            }
        }
    }

    What am I doing wrong?
  2. Juan
    Juan avatar
    2 posts
    Member since:
    Dec 2010

    Posted 06 Jan 2011 Link to this post

    Solved!
  3. DevCraft banner
  4. Justin
    Justin avatar
    35 posts
    Member since:
    Apr 2008

    Posted 01 Aug 2011 Link to this post

    Juan, what was the solution you found?

    Justin
  5. Justin
    Justin avatar
    35 posts
    Member since:
    Apr 2008
Back to Top