This question is locked. New answers and comments are not allowed.
Hi!
I have tabcontrol with custom Header and Content Templates
In the MainPage.xaml.cs I have
The error occurs when I try to add tabControl.Items.Add(new Person()..)
Is it not correct?
Please advice me the correct solution.
Thanks in advance.
Elena
I have tabcontrol with custom Header and Content Templates
| <telerik:RadTabControl x:Name="tabControl" Align="Left" SelectedIndex="0"> |
| <telerik:RadTabControl.ItemContainerStyle> |
| <Style TargetType="telerik:RadTabItem"> |
| <Setter Property="HeaderTemplate"> |
| <Setter.Value> |
| <DataTemplate> |
| <TextBlock Text="{Binding Name}" |
| FontSize="11" |
| Margin="5 0 5 0" |
| VerticalAlignment="Center" /> |
| </DataTemplate> |
| </Setter.Value> |
| </Setter> |
| <Setter Property="ContentTemplate"> |
| <Setter.Value> |
| <DataTemplate> |
| <Grid HorizontalAlignment="Left" VerticalAlignment="Top" Margin="20"> |
| <panels:RadUniformGrid Columns="2"> |
| <TextBlock Text="Name:" /> |
| <TextBox Text="{Binding Name, Mode=TwoWay}" Width="200"/> |
| <TextBlock Text="Date of Birth: " /> |
| <input:RadDatePicker SelectedDate="{Binding DateOfBirth, Mode=TwoWay}" /> |
| <TextBlock Text="Address:" /> |
| <TextBox Text="{Binding Address, Mode=TwoWay}" Width="200"/> |
| </panels:RadUniformGrid> |
| </Grid> |
| </DataTemplate> |
| </Setter.Value> |
| </Setter> |
| </Style> |
| </telerik:RadTabControl.ItemContainerStyle> |
| </telerik:RadTabControl> |
| public Page() |
| { |
| InitializeComponent(); |
| Loaded += new RoutedEventHandler(Page_Loaded); |
| } |
| void Page_Loaded(object sender, RoutedEventArgs e) |
| { |
| tabControl.ItemsSource = new List<Person>() |
| { |
| new Person() |
| { |
| Name = "Joe Cryton", |
| Address = "4 Park Lane av. ", |
| DateOfBirth = new DateTime(1978, 5, 12) |
| }, |
| new Person() |
| { |
| Name = "Denis Lawson", |
| Address = "12 Woodgrave str", |
| DateOfBirth = new DateTime(1980, 12, 1) |
| }, |
| new Person() |
| { |
| Name = "Miles Rush", |
| Address = "7 Lake str.", |
| DateOfBirth = new DateTime(1985, 1, 20) |
| } |
| }; |
| } |
| private void Button_Click(object sender, RoutedEventArgs e) |
| { |
| Person p = new Person() |
| { |
| Name = "Joe Cryton", |
| Address = "4 Park Lane av. ", |
| DateOfBirth = new DateTime(1978, 5, 12) |
| }; |
| tabControl.Items.Add(p); |
| } |
| } |
| public class Person:INotifyPropertyChanged |
| { |
| private String address; |
| /// <summary> |
| /// Gets or sets address of the person. |
| /// </summary> |
| public String Address |
| { |
| get |
| { |
| return this.address; |
| } |
| set |
| { |
| if (this.address != value) |
| { |
| this.address = value; |
| OnPropertyChanged("Address"); |
| } |
| } |
| } |
| private DateTime? dateOfBirth; |
| /// <summary> |
| /// Gets or sets the day of birth of the person. |
| /// </summary> |
| public DateTime? DateOfBirth |
| { |
| get |
| { |
| return this.dateOfBirth; |
| } |
| set |
| { |
| if (this.dateOfBirth != value) |
| { |
| this.dateOfBirth = value; |
| OnPropertyChanged("DateOfBirth"); |
| } |
| } |
| } |
| private String name; |
| /// <summary> |
| /// Gets or sets name of the person. |
| /// </summary> |
| public String Name |
| { |
| get |
| { |
| return this.name; |
| } |
| set |
| { |
| if (this.name != value) |
| { |
| this.name = value; |
| OnPropertyChanged("Name"); |
| } |
| } |
| } |
| /// <summary> |
| /// Called when the value of a property changes. |
| /// </summary> |
| /// <param name="propertyName">The name of the property that has changed.</param> |
| protected virtual void OnPropertyChanged(String propertyName) |
| { |
| if (String.IsNullOrEmpty(propertyName)) |
| { |
| return; |
| } |
| if (PropertyChanged != null) |
| { |
| PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); |
| } |
| } |
| /// <summary> |
| /// Raised when the value of one of the properties changes. |
| /// </summary> |
| public event PropertyChangedEventHandler PropertyChanged; |
| } |
Is it not correct?
Please advice me the correct solution.
Thanks in advance.
Elena
