Mega Code Archive

 
Categories / C# / WPF
 

Label with 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="180">     <Window.Resources>         <ControlTemplate x:Key="labelTemplate" TargetType="{x:Type Label}">             <Border x:Name="border" CornerRadius="4" BorderThickness="3" BorderBrush="DarkGray" Background="{TemplateBinding Property=Background}">                 <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>             </Border>         </ControlTemplate>     </Window.Resources>     <Grid>         <Label Width="100" Height="24"                 Margin="4" Content="Custom Label"                Template="{StaticResource labelTemplate}"                Background="Red"/>     </Grid> </Window>