Skip to main content

How to: Specify DataTemplate used to render labels of LayoutItems

The following code shows how to specify a DataTemplate used to render a label in a custom manner. In the example, the DataTemplate displays a colon after the label’s text.

The DataTemplate is assigned to the LayoutItem.LabelTemplate property. The template is provided via the LayoutGroup.ItemStyle property of the LayoutControl, so it’s applied to all layout items.

The following image shows the result:


<Window x:Class="LabelTemplate_Ex.MainWindow"
        Title="MainWindow" Height="350" Width="525">
    <Grid x:Name="LayoutRoot">
        <lc:LayoutControl Orientation="Vertical">
                <Style TargetType="lc:LayoutItem">
                    <Setter Property="LabelTemplate">
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding}"/>
                                    <TextBlock Text=":" Margin="1,0,0,0"/>

            <lc:LayoutGroup Orientation="Vertical" View="GroupBox" Header="Group 1">
                <lc:LayoutItem Label="Item 1">
                <lc:LayoutItem Label="Item 2">
                <lc:LayoutItem Label="Item 3">