This question is locked. New answers and comments are not allowed.
Hi am using telerik calender control. in that i am using style selector to show the appointment or event . the problem is when i open my calendar screen , some time it used to show style at once at the time of loading some time not .If its not load the appointment for me then to see the appointment i need to go each calendar cell and then it shows me appointment for that cell OR i need to go to other month then its load all available appointment . so for better user experience i want to overcome from this problem . i am giving you my xaml as well as c# code . if you guys can help me out please provide me sure and short way to do that .
c# code
<br><common:LayoutAwarePage<br> x:Class="AFSMOJO.WinUI.Mview"<br> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"<br> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"<br> xmlns:local="using:AFSMOJO.WinUI"<br> xmlns:common="using:MOJO.Common"<br> xmlns:d="http://schemas.microsoft.com/expression/blend/2008"<br> xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"<br> xmlns:telerikInput="using:Telerik.UI.Xaml.Controls.Input"<br> xmlns:telerikGridPrimitives="using:Telerik.UI.Xaml.Controls.Grid.Primitives"<br> xmlns:Input="using:Telerik.UI.Xaml.Controls.Input" <br> xmlns:telerikGrid="using:Telerik.UI.Xaml.Controls.Grid"<br><br> mc:Ignorable="d"><br><br> <common:LayoutAwarePage.Resources><br> <Style TargetType="telerikInput:RadCalendar" x:Key="HeaderStyle"><br> <Setter Property="Background" Value="Transparent"/><br> <Setter Property="Foreground" Value="Black"/><br> <Setter Property="Foreground" Value="Green"/><br> </Style><br> <br><br> <Style x:Key="BaseStatusStyle" TargetType="TextBlock"><br> <Setter Property="FontFamily" Value="Segoe UI Semilight"/><br> <Setter Property="FontSize" Value="14.667"/><br> <Setter Property="Margin" Value="0,0,0,5"/><br> </Style><br> <Style x:Key="StatusStyle" BasedOn="{StaticResource BaseStatusStyle}" TargetType="TextBlock"><br> <Setter Property="Foreground" Value="Green"/><br> </Style><br> <Style x:Key="ErrorStyle" BasedOn="{StaticResource BaseStatusStyle}" TargetType="TextBlock"><br> <Setter Property="Foreground" Value="Blue"/><br> </Style><br><br> </common:LayoutAwarePage.Resources><br> <Page.BottomAppBar><br> <AppBar Background="#7F000000"><br> <Grid Background="Black" ><br> <Image Name="imgok" Source="Assets/ok.PNG" Margin="1079,10,240,16" /><br> <!--<Image Name="imgcancel" Source="Assets/cancel.PNG" Margin="1117,10,183,15" />--><br> <!--<Button Content="OK" Name="btnok" Click="btnok_Click" Margin="1131,11,0,16" ></Button>--><br> <Button Style="{StaticResource ClockAppBarButtonStyle}" Name="Btn_AddReminder" Margin="150,0,0,0" RenderTransformOrigin="-3.175,0.533"></Button><br> <Button Style="{StaticResource PlayAppBarButtonStyle}" Name="btnStartCall" Margin="550,0,0,0" RenderTransformOrigin="-3.175,0.533"></Button><br> <Button Style="{StaticResource AddAppBarButtonStyle }" Name="Btn_AddCall" Margin="250,0,0,0" RenderTransformOrigin="-3.175,0.533"></Button><br> <!--<Button Content="Cancel" Click="btcancel_Click" Name="btcancel" Margin="1190,10,0,17" ></Button>--><br> <Button Style="{StaticResource DirectionsAppBarButtonStyle}" Name="Btn_GetDirections" Margin="350,1,0,-1"></Button><br> <Button Style="{StaticResource EditAppBarButtonStyle}" Name="Btn_Edit" Margin="450,1,0,-1" ></Button><br> <!--<Button x:Name="btnDetails" FontWeight="Bold" FontSize="20" HorizontalAlignment="Center" Content="Details" Margin="173,6,1099,13" Width="103" Height="46" />--><br> <Button Style="{StaticResource HomeAppBarButtonStyle}" Name="Btn_Home" Margin="49,0,0,0"></Button><br> </Grid><br> </AppBar><br> </Page.BottomAppBar><br> <Page.DataContext><br> <local:ViewModelView></local:ViewModelView><br> </Page.DataContext><br> <br> <Grid x:Name="LayoutRoot"><br> <Grid.Background><br> <ImageBrush Stretch="Fill" ImageSource="Images/img-bg_1366x768.jpg"/><br> </Grid.Background><br><br> <Grid.Resources><br> <local:CellModelToEventConverter x:Key="eventConverter" /><br><br> <DataTemplate x:Key="template"><br> <Grid><br> <TextBlock Text="⏰" Foreground="#FF3399FF" FontSize="22" HorizontalAlignment="Right" FontFamily="Segoe UI Symbol" Margin="0,1,2,0" /><br> <TextBlock Text="{Binding Converter={StaticResource eventConverter}}" Foreground="#FF767676" FontSize="13.333" VerticalAlignment="Bottom" Margin="6,0,0,4" /><br> </Grid><br> </DataTemplate><br><br> <local:CustomStyleSelector x:Key="selector" EventTemplate="{StaticResource template}" /><br> </Grid.Resources><br> <TextBlock VerticalAlignment="Top" HorizontalAlignment="Left" Width="308" Text="Month View" Foreground="Black" FontSize="56" FontFamily="Segoe UI" Margin="120,46,0,0" /><br><br> <Grid x:Name="ContentRoot" Margin="100,120,50,20"><br> <Grid.RowDefinitions><br> <RowDefinition Height="Auto"/><br> <RowDefinition Height="*"/><br> <RowDefinition Height="Auto"/><br> </Grid.RowDefinitions><br> <br> <!-- Header --><br><br> <ScrollViewer x:Name="MainScrollViewer" ZoomMode="Disabled" IsTabStop="False" HorizontalScrollBarVisibility="Auto" Padding="0,0,0,20" Margin="20,0,0,0" Grid.RowSpan="2" VerticalScrollMode="Auto" ><br> <Grid><br> <Grid.ColumnDefinitions><br> <ColumnDefinition Width="127*"/><br> <ColumnDefinition Width="1039*"/><br> </Grid.ColumnDefinitions><br> <Grid.RowDefinitions><br> <RowDefinition Height="Auto"/><br> <RowDefinition Height="*"/><br> </Grid.RowDefinitions><br><br> <br> <!-- Content --><br> <Grid Grid.Row="1" Grid.ColumnSpan="2"><br><br> <Grid><br> <Grid.RowDefinitions><br> <RowDefinition Height="Auto"/><br> <RowDefinition Height="Auto"/><br> <RowDefinition Height="Auto"/><br> <RowDefinition Height="Auto"/><br> <RowDefinition Height="Auto"/><br> <RowDefinition Height="Auto"/><br> <RowDefinition Height="Auto"/><br> <RowDefinition Height="*"/><br> </Grid.RowDefinitions><br> <Grid.ColumnDefinitions><br> <ColumnDefinition Width="44.776"/><br> <ColumnDefinition Width="53.224"/><br> <ColumnDefinition Width="17*"/><br> <ColumnDefinition Width="1051*"/><br> </Grid.ColumnDefinitions><br><br> <br> </Grid><br> </Grid><br> <Input:RadCalendar Style="{StaticResource HeaderStyle}" x:Name="calendar" HorizontalAlignment="Left" CellStyleSelector="{StaticResource selector}" VerticalAlignment="Top" Width="1150" Height="600" Foreground="Black" GridLinesBrush="#FF12A4BB" BorderBrush="#FF12A4BB"></Input:RadCalendar><br> </Grid><br> </ScrollViewer><br><br> <!-- Footer --><br><br><br> </Grid><br> <Button x:Name="backButton" Margin="60,65,0,39" Click="backButton_Click"<br> <span class="Apple-tab-span" style="white-space:pre"> </span>Style="{StaticResource MyBackButtonStyle}"<br> <span class="Apple-tab-span" style="white-space:pre"> </span>VerticalAlignment="Stretch"<br> <span class="Apple-tab-span" style="white-space:pre"> </span>AutomationProperties.Name="Back"<br> <span class="Apple-tab-span" style="white-space:pre"> </span>AutomationProperties.AutomationId="BackButton"<br> <span class="Apple-tab-span" style="white-space:pre"> </span>AutomationProperties.ItemType="Navigation Button" Width="47" Height="Auto"/><br><br><br><br> <VisualStateManager.VisualStateGroups><br> <!-- Visual states reflect the application's window size --><br> <VisualStateGroup><br> <VisualState x:Name="DefaultLayout"><br> <Storyboard><br> </Storyboard><br> </VisualState><br><br> <VisualState x:Name="Below768Layout"><br> <Storyboard><br><br> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="ContentRoot"><br> <DiscreteObjectKeyFrame KeyTime="0"><br> <DiscreteObjectKeyFrame.Value><br> <Thickness>20,20,20,20</Thickness><br> </DiscreteObjectKeyFrame.Value><br> </DiscreteObjectKeyFrame><br> </ObjectAnimationUsingKeyFrames><br><br> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.HorizontalAlignment)" Storyboard.TargetName="FooterPanel"><br> <DiscreteObjectKeyFrame KeyTime="0"><br> <DiscreteObjectKeyFrame.Value><br> <HorizontalAlignment>Left</HorizontalAlignment><br> </DiscreteObjectKeyFrame.Value><br> </DiscreteObjectKeyFrame><br> </ObjectAnimationUsingKeyFrames><br><br> </Storyboard><br> </VisualState><br> </VisualStateGroup><br> </VisualStateManager.VisualStateGroups><br> </Grid><br></common:LayoutAwarePage><br><div><br></div>c# code
<br>using AFSMOJO.Biz;<br>using AFSMOJO.Common.Data;<br>using AFSMOJO.WinUI.Log;<br>using System;<br>using System.Collections.Generic;<br>using System.IO;<br>using System.Linq;<br>using System.Runtime.InteropServices.WindowsRuntime;<br>using System.Threading.Tasks;<br>using Telerik.UI.Xaml.Controls.Input;<br>using Telerik.UI.Xaml.Controls.Input.Calendar;<br>using Windows.Foundation;<br>using Windows.Foundation.Collections;<br>using Windows.UI.Xaml;<br>using Windows.UI.Xaml.Controls;<br>using Windows.UI.Xaml.Controls.Primitives;<br>using Windows.UI.Xaml.Data;<br>using Windows.UI.Xaml.Input;<br>using Windows.UI.Xaml.Media;<br>using Windows.UI.Xaml.Navigation;<br>using MOJO.Common;<br>//using Telerik.UI.Xaml.Controls.<br><br>// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238<;br><br>namespace AFSMOJO.WinUI<br>{<br> /// <summary><br> /// An empty page that can be used on its own or navigated to within a Frame.<br> /// </summary><br> public sealed partial class Mview : LayoutAwarePage<br> {<br> public Mview()<br> {<br> this.InitializeComponent();<br> }<br><br> private void backButton_Click(object sender, RoutedEventArgs e)<br> {<br><br> Frame.Navigate(typeof(MyPlan));<br> }<br><br> <br> }<br> public class ViewModelView<br> {<br> public ViewModelView()<br> {<br> this.CreateEvents();<br> }<br> static List<AppointemenTabletdata> listAppointemenTabletdata = new List<AppointemenTabletdata>();<br> private async void CreateEvents()<br> {<br> try<br> {<br><br> <br> List<AppointemenTabletdata> data = new List<AppointemenTabletdata>();<br> data = await GetAppointment();<br> DateTime dt = DateTime.Today;<br> for (int i = 0; i < data.Count; i++)<br> {<br><br> DateTime dueTime1 = new DateTime(data[i].StartTime.Year, data[i].StartTime.Month, data[i].StartTime.Day, dt.Hour, dt.Minute, dt.Second);<br> data[i].StartTime = dueTime1;<br> }<br><br> this.Events = data;<br><br> }<br> catch (Exception ex)<br> {<br> AFS_MOJO_MetroEventSource.Log.Error("CreateEvents():MView" + ex.Message);<br><br> }<br> }<br><br> List<AppointemenTabletdata> objAppointement = new List<AppointemenTabletdata>();<br><br> /// <summary><br> /// shivam<br> /// to get Data From DB to show in calender <br> /// </summary><br> /// <returns></returns><br> public async Task<List<AppointemenTabletdata>> GetAppointment()<br> {<br> Appointment objAppointment = new Appointment();<br> //AFSMOJO.Biz.Appointment objAppointment = new AFSMOJO.Biz.Appointment();<br> try<br> {<br><br> <br> <br> objAppointement = await objAppointment.GetAppointment();<br> return objAppointement;<br> }<br> catch (Exception ex)<br> {<br><br> AFS_MOJO_MetroEventSource.Log.Error("GetAppointment():MView" + ex.Message);<br> return objAppointement;<br><br> }<br> }<br><br> public List<AppointemenTabletdata> Events { get; set; }<br> }<br><br> public class CellModelToEventConverter : IValueConverter<br> {<br> public object Convert(object value, Type targetType, object parameter, string language)<br> {<br> var cellModel = value as CalendarCellModel;<br><br> // Get a reference to the calendar container<br> var calendar = cellModel.Presenter as RadCalendar;<br><br> try<br> {<br><br> <br> <br> // Then you can get a reference to its DataContext (i.e. the page view model that holds the event information)<br> var events = (calendar.DataContext as ViewModelView).Events;<br><br> // return custom label for event cells<br> var eventInfo = events.Where(e => e.StartTime == cellModel.Date).FirstOrDefault();<br> if (eventInfo != null)<br> {<br> return eventInfo.Subject;<br> }<br> }<br> catch (Exception ex)<br> {<br> AFS_MOJO_MetroEventSource.Log.Error("Convert():MView" + ex.Message);<br><br> }<br><br> // return default label for regular cells<br> return cellModel.Label;<br> }<br><br> public object ConvertBack(object value, Type targetType, object parameter, string language)<br> {<br> throw new NotImplementedException();<br> }<br> }<br><br> public class CustomStyleSelector : CalendarCellStyleSelector<br> {<br> public DataTemplate EventTemplate { get; set; }<br><br> protected override void SelectStyleCore(CalendarCellStyleContext context, RadCalendar container)<br> {<br> var events = (container.DataContext as ViewModelView).Events;<br><br> //event can come null so ...<br> if (events != null)<br> {<br> if (events.Where(e => e.StartTime == context.Date).Count() > 0)<br> {<br> context.CellTemplate = this.EventTemplate;<br> }<br> }<br> <br> }<br> }<br>}Plese bind some static data to the list . and let me know if you have any doubt or question .
Note - I am using VS2013 and windows 8.1 .
Note - I am using VS2013 and windows 8.1 .