Tab Control Itemssource

6 posts, 1 answers
  1. Alex Wu
    Alex Wu avatar
    31 posts
    Member since:
    Dec 2009

    Posted 28 Jun 2010 Link to this post

    I followed this link http://www.telerik.com/help/wpf/radtabcontrol-populating-binding-to-collection.html to bind a collection to my tab control. The content is displaying properly but the header is not. My header is still displaying "MiddleLayer.SalesPerson" even though I assigned "Name" to DisplayMemberpath. My code is as below

        <UserControl.Resources>
            <DataTemplate x:Key="salesTemplate">
                <ctrls:AccountSalesPersonUserControl DataContext="{Binding}"></ctrls:AccountSalesPersonUserControl>
            </DataTemplate>
        </UserControl.Resources>

     <telerikPresent:RadTabControl x:Name="SalesPersonTab" ItemsSource="{Binding Path=SelectedItem.SalesPersons, Mode=OneWay}"
                       DisplayMemberPath="Name" ContentTemplate="{StaticResource salesTemplate}" />




  2. Alex Wu
    Alex Wu avatar
    31 posts
    Member since:
    Dec 2009

    Posted 29 Jun 2010 Link to this post

    Anyone? Even a working simple project would help me greatly. Thank you.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Miro Miroslavov
    Admin
    Miro Miroslavov avatar
    588 posts

    Posted 01 Jul 2010 Link to this post

    Hello Alex Wu,

    Can you please find the attached project and check if everything is ok.
    Thank you.

    Greetings,
    Miro Miroslavov
    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
  5. Alex Wu
    Alex Wu avatar
    31 posts
    Member since:
    Dec 2009

    Posted 03 Jul 2010 Link to this post

    Thank you Miro,

    I see that the silverlight example works. I copied and pasted word for word to WPF and it doesn't work. I don't know what I am doing wrong here. Do you have a WPF version of the example or can you take a look at my code? I am going to paste my code here but you can also download the project from my person server at http://awu.dnsalias.com/Telerik/Test.zip

    Xaml:
    <Window xmlns:my="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"  x:Class="WpfApplication1.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:example="clr-namespace:WpfApplication1"
            Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <example:ViewModel x:Key="DataSource" />

            <DataTemplate x:Key="ContentTemplate">
                <Grid>
                    <TextBlock Text="{Binding Age}" />
                </Grid>
            </DataTemplate>

        </Window.Resources>
        <Grid>
            <my:RadTabControl
                 ItemsSource="{Binding Source={StaticResource DataSource}, Path=Persons}"
                 DisplayMemberPath="Name"
                ContentTemplate="{StaticResource ContentTemplate}"
                />
        </Grid>
    </Window>

    Code Behind:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using System.Collections.ObjectModel;

    namespace WpfApplication1
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
            }
        }


        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;
            }
        }

        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;
            }
        }
    }



  6. Answer
    Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 07 Jul 2010 Link to this post

    Hi Alex Wu,

    Try including an ItemTemplate and see if it helps (highlighted are the changes I made to your code):

    <Window
            xmlns:my="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"
            x:Class="WpfApplication1.MainWindow"
            xmlns:example="clr-namespace:WpfApplication1" Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <example:ViewModel x:Key="DataSource" />
            <DataTemplate x:Key="ContentTemplate">
                <Grid>
                    <TextBlock Text="{Binding Age}" />
                </Grid>
            </DataTemplate>
            <DataTemplate x:Key="HeaderTemplate">
                <Grid>
                    <TextBlock Text="{Binding Name}" />
                </Grid>
            </DataTemplate>
        </Window.Resources>
        <Grid>
            <my:RadTabControl ItemsSource="{Binding Source={StaticResource DataSource}, Path=Persons}"
                    ContentTemplate="{StaticResource ContentTemplate}"
                    ItemTemplate="{StaticResource HeaderTemplate}" />
        </Grid>
    </Window>

    On a side note, I'd like to inform you that we've just released an online tool that allows you to reduce the size of your Silverlight applications. For more information, please visit http://blogs.telerik.com/blogs/posts/10-06-10/telerik_assembly_minifier.aspx

    Greetings,
    Kiril Stanoev
    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
  7. Alex Wu
    Alex Wu avatar
    31 posts
    Member since:
    Dec 2009

    Posted 09 Jul 2010 Link to this post

    This worked. Thank you
Back to Top
UI for WPF is Visual Studio 2017 Ready