Binding To Collection from example not working

3 posts, 1 answers
  1. RoxanaC
    RoxanaC avatar
    71 posts
    Member since:
    Dec 2009

    Posted 06 Apr 2010 Link to this post

    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. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 09 Apr 2010 Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. RoxanaC
    RoxanaC avatar
    71 posts
    Member since:
    Dec 2009

    Posted 09 Apr 2010 Link to this post

    Thank you!
    The workaround it's fine for now. 
    All the best!
    Roxana
Back to Top