Bind a TabControl to a data source

image_pdfimage_print


   
 

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

        }
    }
}

   
     


Style With Property Element

image_pdfimage_print


   
    

<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <StackPanel.Resources>
        <Style x:Key="normal">
            <Setter Property="Control.FontSize" Value="24" />
            <Setter Property="Control.HorizontalAlignment" Value="Center" />
            <Setter Property="Control.Margin" Value="24" />
            <Setter Property="Control.Background">
                <Setter.Value>
                    <LinearGradientBrush StartPoint="1,0" EndPoint="1,1">
                        <LinearGradientBrush.GradientStops>
                            <GradientStop Color="LightBlue" Offset="0" />
                            <GradientStop Color="Aquamarine" Offset="1" />
                        </LinearGradientBrush.GradientStops>
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
        </Style>
    </StackPanel.Resources>

    <Button Style="{StaticResource normal}">
        Button Number 1
    </Button>
</StackPanel>

   
    
    
    
     


Style With Triggers

image_pdfimage_print


   
    

<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <StackPanel.Resources>
        <Style x:Key="normal">
            <Setter Property="Control.FontSize" Value="24" />
            <Setter Property="Control.HorizontalAlignment" Value="Center" />
            <Setter Property="Control.Margin" Value="24" />

            <Style.Triggers>
                <Trigger Property="Control.IsMouseOver" Value="true">
                    <Setter Property="Control.FontStyle" Value="Italic" />
                    <Setter Property="Control.Foreground" Value="Blue" />
                </Trigger>

                <Trigger Property="Button.IsPressed" Value="true">
                    <Setter Property="Control.Foreground" Value="Red" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </StackPanel.Resources>

    <Button Style="{StaticResource normal}">
        Button Number 1
    </Button>
</StackPanel>

   
    
    
    
     


Style Slider: Background, IsSnapToTickEnabled, AutoToolTipPlacement, TickFrequency

image_pdfimage_print


   
     
<Window x:Class="ScrollBarCustomThumbSize.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib" 
    Title="" >
    <Window.Resources>
        <Style  TargetType="{x:Type Slider}">
            <Setter Property = "Background" Value = "Red"/>
            <Setter Property = "IsSnapToTickEnabled" Value ="True"/>
            <Setter Property = "TickPlacement" Value ="BottomRight"/>
            <Setter Property = "AutoToolTipPlacement" Value ="BottomRight"/>
            <Setter Property = "TickFrequency" Value ="1"/>
        </Style>


    </Window.Resources>

    <Grid>
        <Slider></Slider>


    </Grid>

</Window>

   
    
    
    
    
     


Normal: Origin at upper left

image_pdfimage_print


   
      
<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 Canvas}">
            <Setter Property="Width" Value="100" />
            <Setter Property="Height" Value="100" />
            <Setter Property="HorizontalAlignment" Value="Center" />
            <Setter Property="VerticalAlignment" Value="Center" />
        </Style>

        <Style TargetType="{x:Type Path}">
            <Setter Property="Fill" Value="Red" />
            <Setter Property="Data">
                <Setter.Value>
                    <EllipseGeometry Center="0 0" RadiusX="5" RadiusY="5" />
                </Setter.Value>
            </Setter>
        </Style>
    </Grid.Resources>
    <Canvas Grid.Column="0">
        <Line X1="0" Y1="0" X2="100" Y2="100" Stroke="Black" />
        <Polyline Points="0 0 0 100 100 100 100 0 0 0" Stroke="Blue" />
        <Path />
    </Canvas>

</Grid>

   
    
    
    
    
    
     


Stroke Start Line Cap

image_pdfimage_print


   
      
<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="FontSize" Value="16" />
            <Setter Property="Margin" Value="24" />
            <Setter Property="VerticalAlignment" Value="Center" />
        </Style>

        <Style TargetType="{x:Type Line}">
            <Setter Property="Grid.Column" Value="1" />
            <Setter Property="Y1" Value="3" />
            <Setter Property="X2" Value="400" />
            <Setter Property="Y2" Value="30" />
            <Setter Property="StrokeThickness" Value="25" />
            <Setter Property="Stroke" Value="Black" />
            <Setter Property="StrokeDashArray" Value="2 2 3 4" />

            <Setter Property="StrokeStartLineCap" Value="{Binding RelativeSource={RelativeSource self}, Path=StrokeDashCap}" />

            <Setter Property="StrokeEndLineCap" Value="{Binding RelativeSource={RelativeSource self}, Path=StrokeDashCap}" />

        </Style>
    </Grid.Resources>

    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>

    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="Auto" />
    </Grid.ColumnDefinitions>

    <!-- PenLineCap.Flat. -->
    <TextBlock Grid.Row="0" Text="PenLineCap.Flat" />
    <Line Grid.Row="0" />

    <!-- PenLineCap.Square. -->
    <TextBlock Grid.Row="1" Text="PenLineCap.Square" />
    <Line Grid.Row="1" StrokeDashCap="Square" />

    <!-- PenLineCap.Round. -->
    <TextBlock Grid.Row="2" Text="PenLineCap.Round" />
    <Line Grid.Row="2" StrokeDashCap="Round" />

    <!-- Triangle.Triangle. -->
    <TextBlock Grid.Row="3" Text="PenLineCap.Triangle" />
    <Line Grid.Row="3" StrokeDashCap="Triangle" />
</Grid>

   
    
    
    
    
    
     


Property Trigger

image_pdfimage_print


   
      

<Window x:Class="PropertyTrigger.Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="PropertyTrigger" Height="300" Width="300">
  <Window.Resources>

    <Style TargetType="{x:Type Button}">
      <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
          <Setter Property="Background" Value="Orange" />
        </Trigger>
      </Style.Triggers>
    </Style>

  </Window.Resources>

  <Grid>
    <Button 
      VerticalAlignment="Top"
      HorizontalAlignment="Stretch"
      Height="46"
      Name="button1"
      >
      Button
    </Button>
    
  </Grid>
</Window>