Hello,
I'm working on a scenario where i have to use 2 different types of appointments, with different properties. both share a common abstract base class, which is derived from the Appointment Class.
public abstract class MyBaseClass : Appointment{ private string _designation; public string Designation { get { return this.Storage<MyBaseClass>()._designation; } set { var storage = this.Storage<MyBaseClass>(); if (value == storage._designation) return; storage._designation = value; this.OnPropertyChanged(() => this.Designation); } }}public class DerivedType : MyBaseClass{ private string _longText; public string LongText { get { return this.Storage<DerivedType>()._longText; } set { var storage = this.Storage<DerivedType>(); if (value == storage._longText) return; storage._longText = value; this.OnPropertyChanged(() => this.LongText); } }}public class OtherType : MyBaseClass{ private bool _myBool; public bool MyBool { get { return this.Storage<OtherType>()._myBool; } set { var storage = this.Storage<OtherType>(); if (value == storage._myBool) return; storage._myBool = value; this.OnPropertyChanged(() => this.MyBool); } }}
When using a ListBox, i would simply put multiple datatemplates with DataType={x:Type ...} into the listbox resources. As this did not work, I tried to override ScheduleViewDataTemplateSelector:
public override DataTemplate SelectTemplate(object item, DependencyObject container, ViewDefinitionBase activeViewDefinition){ Occurrence o = (item as Occurrence); if (o.Appointment is DerivedType) return this.DerivedTypeTemplate;...}
<local:TelerikScheduleTemplateSelector x:Key="ScheduleTemplateSelector"> <local:TelerikScheduleTemplateSelector.DerivedTypeTemplate> <DataTemplate> <Grid Background="LightGray"> <Grid.RowDefinitions> <RowDefinition MinHeight="15"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <Label Grid.Row="0" Content="{Binding Appointment.LongText}" /> <Label Grid.Row="1" MinHeight="30" Margin="2" Background="Green" /> </Grid> </DataTemplate> <local:TelerikScheduleTemplateSelector.OtherTypeTemplate> <DataTemplate> <Grid Background="LightGoldenrodYellow"> <Grid.RowDefinitions> <RowDefinition Height="20"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <CheckBox Grid.Row="0" Margin="2" IsChecked="{Binding Appointment.MyBool}" Content="asdf" /> </Grid> </DataTemplate> </local:TelerikScheduleTemplateSelector.OtherTypeTemplate></local:TelerikScheduleTemplateSelector>
this seems to work partially, but I found some problems:
-> the bindings are not recognized, as I cannot set the DataType to DerivedType or to OtherType
-> Sometimes when switching to other weeks in the scheduleview, I get Binding Errors, because of a missing MyBool Property on DerivedType, and vice-versa
Is there an easier way to get different looks based on the type of the appointment? Could you point me in the right direction, or maybe provide a small sample?
Thanks a lot!
