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

Cannot cast to ViewDefinitionBase

11 Answers 133 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Aaron
Top achievements
Rank 1
Aaron asked on 23 Dec 2011, 04:50 PM
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

11 Answers, 1 is accepted

Sort by
0
Aaron
Top achievements
Rank 1
answered on 23 Dec 2011, 07:26 PM
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

0
Valeri Hristov
Telerik team
answered on 28 Dec 2011, 09:25 AM
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 >>

0
Jay
Top achievements
Rank 1
answered on 05 Feb 2012, 06:57 PM
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>
0
Jay
Top achievements
Rank 1
answered on 05 Feb 2012, 07:43 PM
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>
0
Jay
Top achievements
Rank 1
answered on 05 Feb 2012, 07:59 PM
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 **
0
Valeri Hristov
Telerik team
answered on 09 Feb 2012, 04:35 PM
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 >>
0
Jay
Top achievements
Rank 1
answered on 09 Feb 2012, 05:12 PM
Hi Valeri,

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

Jay
0
Michael MSTG
Top achievements
Rank 1
answered on 19 Apr 2012, 03:58 PM
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.
0
Yana
Telerik team
answered on 24 Apr 2012, 12:00 PM
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 >>

0
Michael MSTG
Top achievements
Rank 1
answered on 24 Apr 2012, 02:50 PM
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.
0
Yana
Telerik team
answered on 27 Apr 2012, 01:13 PM
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 >>

Tags
ScheduleView
Asked by
Aaron
Top achievements
Rank 1
Answers by
Aaron
Top achievements
Rank 1
Valeri Hristov
Telerik team
Jay
Top achievements
Rank 1
Michael MSTG
Top achievements
Rank 1
Yana
Telerik team
Share this question
or