Use a ContentTemplate and determine whether the control contains content.


   
  
<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:c="CodeMapNS"
    x:Class="ContentControlSimple.Page1">
    <StackPanel>
        <StackPanel.Resources>
            <Style x:Key="ContentCtrl" TargetType="{x:Type ContentControl}">
                <Setter Property="Background" Value="Black"/>
                <Setter Property="Foreground" Value="Red"/>
                <Setter Property="FontSize" Value="40"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ContentControl}">
                            <Grid>
                                <Ellipse Width="{TemplateBinding Width}" Height="{TemplateBinding Width}" Fill="{TemplateBinding Background}"/>
                                <ContentPresenter VerticalAlignment="Center"
                                    HorizontalAlignment="Center"/>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <DataTemplate x:Key="template1">
                <TextBlock Text="{Binding}" FontSize="12" FontWeight="Bold" TextWrapping="Wrap"></TextBlock>
            </DataTemplate>
        </StackPanel.Resources>
        <Label Margin="10, 10, 3, 3" Grid.Column="0" Grid.Row="2">
            <ContentControl Width="75" Style="{StaticResource ContentCtrl}" Content="Hello"/>
        </Label>
        <Label Margin="10, 10, 3, 3" Grid.Column="0" Grid.Row="3"
           Background="Blue">
            <ContentControl Name="contCtrl" ContentTemplate="{StaticResource template1}" 
          Content="This is the content of the content control."/>
        </Label>
        <Button Name="btn2" Margin="10, 10, 3, 3" Grid.Column="0" Grid.Row="4" Background="LightBlue" Click="OnClick">
            <TextBlock TextWrapping="Wrap">Click </TextBlock>
        </Button>

    </StackPanel>
</Canvas>
//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Windows.Media;
using System.Collections.ObjectModel;

namespace ContentControlSimple
{
    public partial class Page1 : Canvas
    {
        void OnClick(object sender, RoutedEventArgs e)
        {
            if (contCtrl.HasContent == true)
            {
                MessageBox.Show("contCtrl has content");
            }
        }
    }
}

   
    
     


Enhance the visual appearance of a ContentControl by applying a style.


   
  

<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:c="CodeMapNS"
    x:Class="ContentControlSimple.Page1">
    <StackPanel>
        <StackPanel.Resources>
            <Style x:Key="ContentCtrl" TargetType="{x:Type ContentControl}">
                <Setter Property="Background" Value="Black"/>
                <Setter Property="Foreground" Value="Red"/>
                <Setter Property="FontSize" Value="40"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ContentControl}">
                            <Grid>
                                <Ellipse Width="{TemplateBinding Width}" Height="{TemplateBinding Width}" Fill="{TemplateBinding Background}"/>
                                <ContentPresenter VerticalAlignment="Center"
                                    HorizontalAlignment="Center"/>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <DataTemplate x:Key="template1">
                <TextBlock Text="{Binding}" FontSize="12" FontWeight="Bold" TextWrapping="Wrap"></TextBlock>
            </DataTemplate>
        </StackPanel.Resources>
        <Label Margin="10, 10, 3, 3" Grid.Column="0" Grid.Row="2">
            <ContentControl Width="75" Style="{StaticResource ContentCtrl}" Content="Hello"/>
        </Label>
        <Label Margin="10, 10, 3, 3" Grid.Column="0" Grid.Row="3"
           Background="Blue">
            <ContentControl Name="contCtrl" ContentTemplate="{StaticResource template1}" 
          Content="This is the content of the content control."/>
        </Label>
        <Button Name="btn2" Margin="10, 10, 3, 3" Grid.Column="0" Grid.Row="4" Background="LightBlue" Click="OnClick">
            <TextBlock TextWrapping="Wrap">Click </TextBlock>
        </Button>

    </StackPanel>
</Canvas>
//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Windows.Media;
using System.Collections.ObjectModel;

namespace ContentControlSimple
{
    public partial class Page1 : Canvas
    {
        void OnClick(object sender, RoutedEventArgs e)
        {
            if (contCtrl.HasContent == true)
            {
                MessageBox.Show("contCtrl has content");
            }
        }
    }
}

   
    
     


ControlTemplates and style xaml file

   
  
<Window x:Class="ControlTemplates.GradientButtonTest"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="GradientButtonTest" Height="280" Width="322"
    >
  <Window.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="a.xaml"></ResourceDictionary>
      </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </Window.Resources>
  <StackPanel>
    <Button Margin="10" Padding="5" Click="Clicked" Name="cmdOne">A Simple Button with a Custom Template</Button>
    <Button Margin="10" Padding="5" IsEnabled="False" Click="Clicked" Name="cmdFour" >A Disabled Button</Button>
    <CheckBox Margin="10" Checked="chkGreen_Checked" Unchecked="chkGreen_Unchecked">Use Alternate Theme</CheckBox>
  </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;

namespace ControlTemplates
{

    public partial class GradientButtonTest : System.Windows.Window
    {

        public GradientButtonTest()
        {
            InitializeComponent();
        }

        private void Clicked(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("You clicked " + ((Button)sender).Name);
        }

        private void chkGreen_Checked(object sender, RoutedEventArgs e)
        {
            ResourceDictionary resourceDictionary = new ResourceDictionary();
            resourceDictionary.Source = new Uri("a.xaml", UriKind.Relative);
            this.Resources.MergedDictionaries[0] = resourceDictionary;                
        }

        private void chkGreen_Unchecked(object sender, RoutedEventArgs e)
        {
            ResourceDictionary resourceDictionary = new ResourceDictionary();
            resourceDictionary.Source = new Uri("b.xaml", UriKind.Relative);
            this.Resources.MergedDictionaries[0] = resourceDictionary;                
        }
    }
}

   
    
     


Get The actual width of the border in the ControlTemplate


   
  

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WPF" Height="100" Width="160">

    <Window.Resources>
        <ControlTemplate x:Key="buttonTemplate" TargetType="{x:Type Button}">
            <Border x:Name="border" BorderThickness="3" BorderBrush="DarkGray" Background="LightGray">
                <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Border>
            <ControlTemplate.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter TargetName="border" Property="Background" Value="Orange"/>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </Window.Resources>
    <Grid>
        <Button x:Name="button" Height="24" HorizontalAlignment="Stretch" Content="Custom Template"
                Template="{StaticResource buttonTemplate}" Click="Button_Click">
        </Button>
    </Grid>
</Window>
//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;

namespace WpfApplication1
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Border borderInTemplate = (Border)button.Template.FindName("border", button);
            Console.WriteLine(borderInTemplate.GetValue(Border.ActualWidthProperty));
        }
    }
}

   
    
     


Finding the border that is generated by the ControlTemplate of the Button


   
  

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WPF" Height="100" Width="160">

    <Window.Resources>
        <ControlTemplate x:Key="buttonTemplate" TargetType="{x:Type Button}">
            <Border x:Name="border" BorderThickness="3" BorderBrush="DarkGray" Background="LightGray">
                <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Border>
            <ControlTemplate.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter TargetName="border" Property="Background" Value="Orange"/>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </Window.Resources>
    <Grid>
        <Button x:Name="button" Height="24" HorizontalAlignment="Stretch" Content="Custom Template"
                Template="{StaticResource buttonTemplate}" Click="Button_Click">
        </Button>
    </Grid>
</Window>
//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;

namespace WpfApplication1
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Border borderInTemplate = (Border)button.Template.FindName("border", button);
            Console.WriteLine(borderInTemplate.GetValue(Border.ActualWidthProperty));
        }
    }
}

   
    
     


Use ControlTemplate and event handler


   
  
<Window x:Class="ControlTemplate.Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="ControlTemplate" Height="300" Width="300">
  <Window.Resources>
    <ControlTemplate x:Key="customizeButton" TargetType="{x:Type Button}">
      <Grid>
        <Ellipse Width="100" Height="100" Fill="Green" 
          Stroke="Red" StrokeThickness="2"/>
        <ContentPresenter VerticalAlignment="Center"
          HorizontalAlignment="Center"></ContentPresenter>
      </Grid>
    </ControlTemplate>
  </Window.Resources>
  <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
    <Button Name="button1" Template="{StaticResource customizeButton}"  
      Foreground="White" Click="button1_Click">Press Me!</Button>
  </Grid>
</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;


namespace ControlTemplate
{
  public partial class Window1 : System.Windows.Window
  {

    public Window1()
    {
      InitializeComponent();
    }

    private void button1_Click(object sender, RoutedEventArgs e)
    {
      MessageBox.Show("Hello WPF!");
    }

  }
}

   
    
     


ControlTemplate that Respects More Properties


   
      


<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="">
        
        
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Grid.Resources>
    <ControlTemplate x:Key="buttonTemplate" TargetType="{x:Type Button}">
      <Grid>
        <Ellipse x:Name="outerCircle">
          <Ellipse.Fill>
            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
              <GradientStop Offset="0"
                Color="{Binding RelativeSource={RelativeSource TemplatedParent},
                Path=Background.Color}"/>
                <GradientStop Offset="1" Color="Red"/>
              </LinearGradientBrush>
          </Ellipse.Fill>
        </Ellipse>
        <Viewbox>
          <ContentPresenter Margin="{TemplateBinding Padding}"/>
        </Viewbox>
      </Grid>
      <ControlTemplate.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
          <Setter TargetName="outerCircle" Property="Fill" Value="Orange"/>
        </Trigger>
        <Trigger Property="IsPressed" Value="True">
          <Setter Property="RenderTransform">
            <Setter.Value>
              <ScaleTransform ScaleX=".9" ScaleY=".9"/>
            </Setter.Value>
          </Setter>
          <Setter Property="RenderTransformOrigin" Value=".5,.5"/>
        </Trigger>
      </ControlTemplate.Triggers>
    </ControlTemplate>
  </Grid.Resources>
  <StackPanel Orientation="Horizontal">
    <Button Template="{StaticResource buttonTemplate}" Height="100" Width="100" FontSize="80" Background="Black"
    Padding="20" Margin="5">1</Button>
  </StackPanel>
</Grid>

</Window>