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

Binding To Collection from example not working

2 Answers 42 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
RoxanaC
Top achievements
Rank 1
RoxanaC asked on 06 Apr 2010, 07:55 AM
Hello! I was trying to get advantage from the RadTabControl component in my project and have it bounded to a collection I am going to use. I follow all the steps in the documentation, but in the end the tab names are still the name of the class and not some property string I want to use. I even made a project using your own classes (Person & ViewModel) thinking that something is wrong with my code and I still see "DataInfo.Person" at the name of each tab (DataInfo is my namespace)
I am using exactly your code:

namespace DataInfo { 
    public class Person { 
        public Person( string name, int age ) { 
            this.Name = name; 
            this.Age = age; 
        } 
        public string Name { 
            get
            set
        } 
        public int Age { 
            get
            set
        } 
    } 

namespace DataInfo { 
    public class ViewModel { 
        public ViewModel() { 
            this.Persons = new ObservableCollection<Person>(); 
            this.Persons.Add( new Person( "Ivan", 23 ) ); 
            this.Persons.Add( new Person( "Stefan", 34 ) ); 
            this.Persons.Add( new Person( "Maria", 16 ) ); 
            this.Persons.Add( new Person( "Michael", 78 ) ); 
        } 
        public ObservableCollection<Person> Persons { 
            get
            set
        } 
    } 


<UserControl x:Class="DataInfo.TabControl" 
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             xmlns:DataInfo="clr-namespace:DataInfo" 
             xmlns:Controls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"
    <UserControl.Resources> 
        <DataInfo:ViewModel x:Key="DataSource" /> 
        <DataTemplate x:Key="ContentTemplate"
            <Grid> 
                <TextBlock Text="{Binding Age}" /> 
            </Grid> 
        </DataTemplate> 
    </UserControl.Resources> 
    <Grid x:Name="LayoutRoot" 
          Background="White"
        <Controls:RadTabControl x:Name="radTabControl" 
                                Margin="8" 
                                ItemsSource="{Binding Source={StaticResource DataSource}, Path=Persons}" 
                                DisplayMemberPath="Name" 
                                ContentTemplate="{StaticResource ContentTemplate}" /> 
 
    </Grid> 
</UserControl> 

Is there something I've misunderstood?

Thank you!
Roxana











2 Answers, 1 is accepted

Sort by
0
Accepted
Tina Stancheva
Telerik team
answered on 09 Apr 2010, 07:34 AM
Hi RoxanaC,

Thank you for reporting this issue. I logged it as a bug and we will try to fix it as soon as possible. I also updated your Telerik points accordingly.

In the meantime, you can use Style binding for the  HeaderTemplate and the ContentTemplate, like this:
<telerikNavigation:RadTabControl Name="radTabControl1" Grid.Row="0" Grid.Column="0">
    <telerikNavigation:RadTabControl.ItemContainerStyle>
        <Style TargetType="telerikNavigation:RadTabItem">
            <Setter Property="HeaderTemplate"
                  Value="{StaticResource HeaderTemplate}" />
            <Setter Property="ContentTemplate"
                  Value="{StaticResource ItemTemplate}" />
        </Style>
    </telerikNavigation:RadTabControl.ItemContainerStyle>
</telerikNavigation:RadTabControl>

Please take a look at the example that I attached and let me know if it works for you or if you need more info.

Greetings,
Tina Stancheva
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
RoxanaC
Top achievements
Rank 1
answered on 09 Apr 2010, 09:27 AM
Thank you!
The workaround it's fine for now. 
All the best!
Roxana
Tags
TabControl
Asked by
RoxanaC
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
RoxanaC
Top achievements
Rank 1
Share this question
or