Bind a TabControl to a data source : TabControl « Windows Presentation Foundation « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Windows Presentation Foundation » TabControlScreenshots 
Bind a TabControl to a data source
Bind a TabControl to a data source
 

<Window x:Class="TabControlUsingItemTemplate.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:src="clr-namespace:TabControlUsingItemTemplate"
    Title="TabControlUsingItemTemplate" Height="300" Width="300">
  <Window.Resources>
    <ObjectDataProvider x:Key="TabListResource" ObjectType="{x:Type src:TabList}" />
    <DataTemplate x:Key="HeaderTemplate">
      <TextBlock Text="{Binding Path=Header}" />
    </DataTemplate>
    <DataTemplate x:Key="ContentTemplate">
      <TextBlock Text="{Binding Path=Content}" />
    </DataTemplate>
  </Window.Resources>

  <DockPanel>
    <TabControl ItemsSource="{Binding Source={StaticResource TabListResource}}"
                  ItemTemplate="{StaticResource HeaderTemplate}"
                  ContentTemplate="{StaticResource ContentTemplate}"/>

  </DockPanel>

</Window>
//File:Window.xaml.cs
using System;
using System.Collections.Generic;
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.Shapes;
using System.Collections.ObjectModel;
namespace TabControlUsingItemTemplate
{
    public partial class Window1 : System.Windows.Window
    {
        public Window1()
        {
            InitializeComponent();
        }
    }
    public class TabItemData
    {
        private string _header;
        private string _content;

        public TabItemData(string header, string content)
        {
            _header = header;
            _content = content;
        }
        public string Header
        {
            get return _header; }
        }
        public string Content
        {
            get return _content; }
        }
    }
    public class TabList : ObservableCollection<TabItemData>
    {
        public TabList(): base()
        {

            Add(new TabItemData("Header 1""Content 1"));
            Add(new TabItemData("Header 2""Content 2"));
            Add(new TabItemData("Header 3""Content 3"));

        }
    }
}

   
  
Related examples in the same category
1.Frame background, TabControl background
2.TabControl and Frame source
3.Style TabItemStyle TabItem
4.Style a TabControl using templates for the TabControl and TabItem elements.Style a TabControl using templates for the TabControl and TabItem elements.
5.TabItem HeaderTabItem Header
6.Tab page headersTab page headers
7.Put Different Objects to TabItemPut Different Objects to TabItem
8.Tab TestTab Test
9.Binds a TabControl to a collection of Employee objectsBinds a TabControl to a collection of Employee objects
10.Use a GroupBox control to create a container for a TabControl.Use a GroupBox control to create a container for a TabControl.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.