Emboss Text


   
     



<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid.Resources>
        <Style TargetType="{x:Type TextBlock}">
            <Setter Property="FontFamily" Value="Times New Roman" />
            <Setter Property="FontSize" Value="144" />
            <Setter Property="HorizontalAlignment" Value="Center" />
            <Setter Property="VerticalAlignment" Value="Center" />
        </Style>
    </Grid.Resources>

    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>

    <TextBlock Foreground="{DynamicResource 
                    {x:Static SystemColors.GrayTextBrushKey}}">
        Emboss
        <TextBlock.RenderTransform>
            <TranslateTransform X="2" Y="2" />
        </TextBlock.RenderTransform>
    </TextBlock>


    <TextBlock Foreground="{DynamicResource 
                    {x:Static SystemColors.WindowBrushKey}}">
        Emboss
    </TextBlock>


</Grid>

   
    
    
    
    
     


TextBlock VerticalAlignment


   
     

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Class="TextDecorationExample.Window1"
  Title="TextDecoration Example"
  Width="720"
  Height="400">
  <StackPanel>
      <TextBlock 
        FontSize="24" 
        Width="180" 
        VerticalAlignment="Center" 
        TextDecorations="OverLine">The lazy dog</TextBlock>
  </StackPanel>
</Window>

   
    
    
    
    
     


Use a GroupBox control to create a container for a TabControl.


   
 

<Page x:Class="GroupBoxExample.Page1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Loaded="OnLoad" Name="GroupBoxPage">

    <DockPanel>
        <GroupBox Width="300" Height="410">
            <GroupBox.Header>
                <Label>Title of the GroupBox</Label>
            </GroupBox.Header>
            <StackPanel>
                <TabControl Name="myTabControl" TabStripPlacement="Top" Margin="0, 0, 0, 10" Height="350">
                    <TabItem Name="PersonalInfo">
                        <TabItem.Header>_Personal</TabItem.Header>
                        <StackPanel>
                            <TextBlock>Employee</TextBlock>
                            <TextBlock>Select your name</TextBlock>
                            <ListBox Name="empName" SelectionChanged="updateSummary">
                                <ListBoxItem IsSelected="true">A</ListBoxItem>
                                <ListBoxItem>B</ListBoxItem>
                                <ListBoxItem>C</ListBoxItem>
                                <ListBoxItem>D</ListBoxItem>
                            </ListBox>
                        </StackPanel>
                    </TabItem>
                    <TabItem>
                        <TabItem.Header>_Job</TabItem.Header>
                        <StackPanel>
                            <TextBlock>Select a job</TextBlock>
                            <ListBox Name ="job" SelectionChanged="updateSummary">
                                <ListBoxItem IsSelected="true">A</ListBoxItem>
                                <ListBoxItem>B</ListBoxItem>
                                <ListBoxItem>C</ListBoxItem>
                                <ListBoxItem>D</ListBoxItem>
                            </ListBox>
                        </StackPanel>
                    </TabItem>
                    <TabItem Name="Summary" >
                        <TabItem.Header>Su_mmary</TabItem.Header>
                        <StackPanel>
                            <TextBlock Name="emp"/>
                            <TextBlock Name="ejob"/>
                            <TextBlock Name="eskill"/>
                        </StackPanel>
                    </TabItem>
                </TabControl>
                <Button Content="Show Summary" Click="goToSummaryTab"/>
            </StackPanel>
        </GroupBox>
    </DockPanel>
</Page>

//File:Window.xaml.cs

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace GroupBoxExample
{
    public partial class Page1 : Page
    {
        private void displayData()
        {
            ListBoxItem lbi = empName.SelectedItem as ListBoxItem;
            emp.Text = "Name: " + lbi.Content.ToString();
            lbi = job.SelectedItem as ListBoxItem;
            ejob.Text = "Job: " + lbi.Content.ToString();
            eskill.Text = "Skill: " + lbi.Content.ToString();
        }
        private void OnLoad(object sender, RoutedEventArgs e)
        {
            displayData();
        }
        private void updateSummary(object sender, RoutedEventArgs e)
        {
            if (GroupBoxPage.IsLoaded)
                displayData();
        }
        private void goToSummaryTab(object sender, RoutedEventArgs e)
        {
            displayData();
            Summary.IsSelected = true;
        }
    }
}

   
     


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"));

        }
    }
}

   
     


Binds a TabControl to a collection of Employee objects


   
 

<Window x:Class="TabControlContentTemplateSelector.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:src="clr-namespace:TabControlContentTemplateSelector"  
    Title="TabControlContentTemplateSelector">
  <Window.Resources>
    <src:People x:Key="MyFriends"/>
    <DataTemplate x:Key="DetailTemplate">
        <StackPanel>
          <TextBlock Text="First Name:"/>
          <TextBlock Text="{Binding Path=FirstName}"/>
          <TextBlock Text="Last Name:"/>
          <TextBlock Text="{Binding Path=LastName}"/>
        </StackPanel>
    </DataTemplate>
    <DataTemplate x:Key="SeattleTemplate">
      <DataTemplate.Resources>
        <Style TargetType="TextBlock">
          <Setter Property="FontSize" Value="16"/>
        </Style>
      </DataTemplate.Resources>
     <StackPanel>
          <TextBlock Text="Please welcome"/>
          <TextBlock Text="{Binding Path=FirstName}"/>
          <TextBlock Text=" "/>
          <TextBlock Text="{Binding Path=LastName}"/>
    </StackPanel>
    </DataTemplate>

    <src:EmployeeTemplateSelector x:Key="EmployeeSelector"/>
  </Window.Resources>

  <StackPanel VerticalAlignment="Center">
    <TabControl Name="tabCtrl1" Width="400" Height="200" 
             ItemsSource="{Binding Source={StaticResource MyFriends}}"
             ContentTemplateSelector="{StaticResource EmployeeSelector}"/>
    <Button Width="100" Margin="10" Name="infoBtn"
            Click="infoBtn_Click">
      _Get Information
    </Button>
  </StackPanel>
</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.ComponentModel;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
namespace TabControlContentTemplateSelector
{
    public class Employee : INotifyPropertyChanged
    {
        private string firstname;
        private string lastname;

        public event PropertyChangedEventHandler PropertyChanged;

        public Employee()
        {
        }

        public Employee(string first, string last)
        {
            this.firstname = first;
            this.lastname = last;
        }

        public override string ToString()
        {
            return firstname.ToString();
        }

        public string FirstName
        {
            get { return firstname; }
            set
            {
                firstname = value;
                OnPropertyChanged("FirstName");
            }
        }

        public string LastName
        {
            get { return lastname; }
            set
            {
                lastname = value;
                OnPropertyChanged("LastName");
            }
        }
        protected void OnPropertyChanged(string info)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(info));
            }
        }
    }

    public class People : ObservableCollection<Employee>
    {
        public People()
            : base()
        {
            Add(new Employee("A", "B"));
            Add(new Employee("C", "D"));
            Add(new Employee("E", "F"));
            Add(new Employee("G", "H"));
            Add(new Employee("I", "J"));
        }
    }

    public partial class Window1 : System.Windows.Window
    {

        public Window1()
        {
            InitializeComponent();
        }

        void infoBtn_Click(object sender, RoutedEventArgs e)
         {
            if (tabCtrl1.SelectedContent is Employee)
            {
                Employee selectedEmployee = tabCtrl1.SelectedContent as Employee;
                StringBuilder personInfo = new StringBuilder();

                personInfo.Append(selectedEmployee.FirstName);
                personInfo.Append(" ");
                personInfo.Append(selectedEmployee.LastName);
                MessageBox.Show(personInfo.ToString());
            }
        }
    }
    public class EmployeeTemplateSelector : DataTemplateSelector
    {
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            if (item is Employee)
            {
                Employee person = item as Employee;
                Window win = Application.Current.MainWindow;
                return win.FindResource("SeattleTemplate") as DataTemplate;
                //return win.FindResource("DetailTemplate") as DataTemplate;

            }
            return null;
        }

    }
}

   
     


Tab Test


   
      
<Window x:Class="Content.TabTest"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="TabTest" Height="300" Width="300">
  <TabControl Margin="5">
    <TabItem Header="Tab One">
      <StackPanel Margin="3">
        <CheckBox Margin="3">Setting One</CheckBox>
        <CheckBox Margin="3">Setting Two</CheckBox>
        <CheckBox Margin="3">Setting Three</CheckBox>
      </StackPanel>
    </TabItem>
    <TabItem Header="Tab Two"></TabItem>
  </TabControl>
</Window>

   
    
    
    
    
    
     


Put Different Objects to TabItem


   
      

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      WindowTitle="Canvas Sample">

    <StackPanel>
        <TabControl MinHeight="500" MinWidth="400">
            <TabItem  Header="Canvas" IsSelected="True">
                <Canvas Height="400" Width="400">
                     <Rectangle Width="100" Height="100" Fill="red"/>
                </Canvas>
            </TabItem>
            <TabItem Header="XAML Markup">
                <TextBlock  xml:space="preserve">
                       &amp;lt;&amp;gt;
                </TextBlock>
            </TabItem>

            <TabItem  Header="Description">
                <StackPanel>
                    <TextBlock>Sample</TextBlock>
                </StackPanel>
            </TabItem>
        </TabControl>
        <TextBlock >All rights reserved.</TextBlock>
    </StackPanel>

</Page>