Cannot cast to ViewDefinitionBase

12 posts, 0 answers
  1. Aaron
    Aaron avatar
    29 posts
    Member since:
    May 2011

    Posted 23 Dec 2011 Link to this post

    Hi,

    I've set up a RadScheduleView according to that of the sample project in the RadScheduleView documentation (ScheduleView_EF_SL). When I run the application, the InitializeComponent() method in the constructor of the Usercontrol that contains the RadScheduleView throws the following exception.

    XamlParseException
    -> InnerException: InvalidCastException
    -> Message:            Unable to cast object of type 'Telerik.Windows.Controls.WeekViewDefinition' to type
                                   'Telerik.Windows.Controls.ViewDefinitionBase'.

    I am able to compile and run the sample project from the documentation.  I've compared that project and my own, but I haven't been able to figure out what the problem is.  This is the ScheduleView XAML:

    <telerik:RadDocking.DocumentHost>
    <Grid x:Name="gridDocumentHost">
            <telerik:RadBusyIndicator IsBusy="{Binding IsLoading}">
                            <telerik:RadScheduleView x:Name="radScheduleView1" AppointmentCreated="RadScheduleView_AppointmentCreated"
                                                 AppointmentDeleted="RadScheduleView_AppointmentDeleted"
                                                 AppointmentEdited="RadScheduleView_AppointmentEdited"
                                                 AppointmentsSource="{Binding Appointments}"
                                                 ResourceTypesSource="{Binding ResourceTypes}"
                                                 TimeMarkersSource="{Binding TimeMarkers}"
                                                 CategoriesSource="{Binding Categories}"
                                                     ActiveViewDefinitionIndex="1"
                                                 VisibleRangeChangedCommand="{Binding VisibleRangeChanged}"
                                                 VisibleRangeChangedCommandParameter="{Binding VisibleRange, RelativeSource={RelativeSource Self}}">
                                <telerik:RadScheduleView.ViewDefinitions>
                                    <telerik:MonthViewDefinition />
                                    <telerik:WeekViewDefinition />
                                    <telerik:DayViewDefinition />
                                </telerik:RadScheduleView.ViewDefinitions>
                            </telerik:RadScheduleView>
                        </telerik:RadBusyIndicator>
                    </Grid>
                </telerik:RadDocking.DocumentHost>

    And here is the code:

        public partial class ucPersonalToDo : UserControl
        {
            
    public ucPersonalToDo()
            {
                InitializeComponent();
            }

            
    private void RadRibbonButton_Click(object sender, RoutedEventArgs e)
            {

            }

            
    private void RadScheduleView_AppointmentDeleted(object sender, Telerik.Windows.Controls.AppointmentDeletedEventArgs e)
            {
                ScheduleViewRepository.SaveData();
            }

            
    private void RadScheduleView_AppointmentEdited(object sender, Telerik.Windows.Controls.AppointmentEditedEventArgs e)
            {
                ScheduleViewRepository.SaveData();
            }

            
    private void RadScheduleView_AppointmentCreated(object sender, Telerik.Windows.Controls.AppointmentCreatedEventArgs e)
            {
                ScheduleViewRepository.SaveData();
            }
        }

    I'm using RadControls for Silverlight 4 2011.3.1116.1040, VS2010, and I'm running on Windows 7 Home Premium x64.


    Much appreciated,
    Aaron
  2. Aaron
    Aaron avatar
    29 posts
    Member since:
    May 2011

    Posted 23 Dec 2011 Link to this post

    I was able to work around this issue by removing the  <telerik:RadScheduleView.ViewDefinitions>
    tag from the XAML and modifying the constructor like so:

    public ucPersonalToDo()
    {
            InitializeComponent();
            
    this.radScheduleView1.ViewDefinitions.Add(new MonthViewDefinition());
            
    this.radScheduleView1.ViewDefinitions.Add(new WeekViewDefinition());
            
    this.radScheduleView1.ViewDefinitions.Add(new DayViewDefinition());
    }

    I could've sworn I'd tried this before, but maybe I'd forgotten something.  Who knows.  At any rate, this works, but I'm still curious as to why I was having trouble with the XAML.


    Cheers,
    Aaron

  3. DevCraft banner
  4. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 28 Dec 2011 Link to this post

    Hello Aaron,

    Most probably you have references to both Scheduler and ScheduleView assemblies. They both contain classes that are named DayViewDefinition, WeekViewDefinition, etc. hence the name collision in XAML. If you remove the Telerik.Windows.Controls.Scheduler.dll from your references the problem should disappear.


    Kind regards,
    Valeri Hristov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  5. Jay
    Jay avatar
    5 posts
    Member since:
    Jan 2012

    Posted 05 Feb 2012 Link to this post

    I'm using a combination of Expression Blend 4 and Visual Studio 2010. I get an unable to cast object of type 'Telerick.Windows.Controls.DayViewDefinition' to type 'Telerik.Windows.Controls.ViewDefinitionBase'.

    I do not have a reference to Telerik.Windows.Controls.Schedule. I am using version 2011.3.1220.1040 (Trial version) of ScheduleView.

    Please find my xaml below:

    <UserControl
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
     
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     
    xmlns:local="clr-namespace:Genius"
     
    xmlns:Genius_ViewModels="clr-namespace:Genius.ViewModels"
     
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
     
    mc:Ignorable="d"
     
    x:Class="Genius.ClientSchedulerControl"
     
    d:DesignWidth="1024" d:DesignHeight="768">
     
    <UserControl.Resources>
       
    <Genius_ViewModels:ClientSchedulerControlViewModel x:Key="ClientSchedulerControlViewModelDataSource" d:IsDataSource="True"/>
     
    </UserControl.Resources>
     
    <Grid x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource ClientSchedulerControlViewModelDataSource}}">
        <telerik:RadScheduleView d:LayoutOverrides="Width, Height" AppointmentsSource="{Binding AppointmentsViewModel.Appointments}" ActiveViewDefinitionIndex="0">
          <telerik:RadScheduleView.ViewDefinitions>
            <telerik:DayViewDefinition/>
            <telerik:WeekViewDefinition/>
            <telerik:MonthViewDefinition/>
            <telerik:TimelineViewDefinition/>
          </telerik:RadScheduleView.ViewDefinitions>
        </telerik:RadScheduleView>
      </Grid>
    </UserControl>
  6. Jay
    Jay avatar
    5 posts
    Member since:
    Jan 2012

    Posted 05 Feb 2012 Link to this post

    Please find below the xaml for MainPage.xaml

        xmlns:local="clr-namespace:Genius" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
        x:Class="Genius.MainPage"
        Width="1024" Height="768">
     
        <Grid x:Name="LayoutRoot" Background="White">
            <local:ClientSchedulerControl/>
        </Grid>
    </UserControl>
  7. Jay
    Jay avatar
    5 posts
    Member since:
    Jan 2012

    Posted 05 Feb 2012 Link to this post

    I also get the message "Please provide an appointments source"

    ** I'm managed to resolve this now but the other error is still an issue **
  8. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 09 Feb 2012 Link to this post

    Hi,

    The only reason for the occurrence of the "Unable to cast object of type 'Telerick.Windows.Controls.DayViewDefinition' to type 'Telerik.Windows.Controls.ViewDefinitionBase'" exception that we are aware of is referencing both Telerik.Windows.Controls.Scheduler and Telerik.Windows.Controls.ScheduleView assemblies in the application. To confirm this is not the case, could you please, prepare and send us a simple application that could be used to observe the problem and we will immediately respond with a solution.

    Kind regards,
    Valeri Hristov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  9. Jay
    Jay avatar
    5 posts
    Member since:
    Jan 2012

    Posted 09 Feb 2012 Link to this post

    Hi Valeri,

    Thank you for your response. Closing and reopening Expression Blend resolved this issue.

    Jay
  10. Michael MSTG
    Michael MSTG avatar
    46 posts
    Member since:
    Aug 2012

    Posted 19 Apr 2012 Link to this post

    Is this still the case?  We are using the scheduler assembly for one aspect of an application and would like to use the schedule view for a type of dashboard.  If it is not possible to use both within a project, what would be a good alternative since the RadChart does not support timeline type of functionality.
  11. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 24 Apr 2012 Link to this post

    Hello Michael,

    To resolve conflict between namespaces you can use aliases.  Please follow the link below for more details:
    http://www.switchonthecode.com/tutorials/csharp-snippet-the-many-uses-of-the-using-keyword

    Kind regards,
    Yana
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  12. Michael MSTG
    Michael MSTG avatar
    46 posts
    Member since:
    Aug 2012

    Posted 24 Apr 2012 Link to this post

    OK perhaps you did not read this thread?  This was about the conflict within XAML and being able to use the ScheduleView control while still having the Scheduler assembly reference; this had nothing to do with setting up code from code behind.
  13. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 27 Apr 2012 Link to this post

    Hello Michael,

    You are right, I am sorry for my misunderstanding.

    At the moment we are not aware of an easy way to have both controls referenced in the same project. Our recommendation is to replace completely the Scheduler with RadScheduleView. Please note that since Q1 2012 RadScheduler is removed from the installation and you will not be able to upgrade.

    All the best,
    Yana
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top
DevCraft banner