Skip to main content

LayoutItem.Label Property

Gets or sets a label for the current LayoutItem. This is a dependency property.

Namespace: DevExpress.Xpf.LayoutControl

Assembly: DevExpress.Xpf.LayoutControl.v14.2.dll

#Declaration

public object Label { get; set; }

#Property Value

Type Description
Object

An object that represents a label for the current LayoutItem.

#Remarks

Typically, you assign a text string to the Label property. However, you can assign any object to the Label property, and then specify how the object should be rendered via the LayoutItem.LabelTemplate property.

A label's style can be customized via the LayoutItem.LabelStyle property.

#Example

The following code shows how to change the styles of labels for individual layout items, or all of them. The style is changed via the LayoutItem.LabelStyle property.

Styles of layout items' labels can be customized via the LayoutItem.LabelStyle property. This example demonstrates two approaches to changing the LabelStyle property:

  • for all layout items belonging to a container - via the container's LayoutGroup.ItemStyle property. In this example, this style specifies the blue foreground color for labels
  • for individual layout items - directly via their LayoutItem.LabelStyle properties. In the example, this style, applied to the first layout item (Model), paints the item's label in red.

The following image shows the result:

LabelStyle_Ex

<UserControl x:Class="LabelStyle_Ex.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:lc="http://schemas.devexpress.com/winfx/2008/xaml/layoutcontrol"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">

    <UserControl.Resources>
        <!--The default style for layout items: labels are painted in blue-->
        <Style x:Key="DefaultLayoutItemStyle" TargetType="lc:LayoutItem">
            <Setter Property="LabelStyle">
                <Setter.Value>
                    <Style TargetType="lc:LayoutItemLabel">
                        <Setter Property="Foreground" Value="#FF0000FF"/>
                    </Style>
                </Setter.Value>
            </Setter>
            <Setter Property="ElementSpace" Value="8"/>
        </Style>
        <!--A custom style to paint labels in red-->
        <Style x:Key="MyLabelStyle" TargetType="lc:LayoutItemLabel">
            <Setter Property="Foreground" Value="#FFFF0000"/>
        </Style>

    </UserControl.Resources>


    <!--Apply the default style to layout items-->
    <lc:LayoutControl x:Name="LayoutRoot" ItemStyle="{StaticResource DefaultLayoutItemStyle}" >

        <!--Apply the custom style to the first layout item-->
        <lc:LayoutGroup Header="Group 1" View="GroupBox" Orientation="Vertical">
            <lc:LayoutItem Label="Model:" LabelStyle="{StaticResource MyLabelStyle}">
                <TextBlock Text="530i" />
            </lc:LayoutItem>
            <lc:LayoutItem Label="HP:" >
                <TextBlock Text="225" />
            </lc:LayoutItem>
            <lc:LayoutItem Label="# of Gears:">
                <TextBlock Text="5" />
            </lc:LayoutItem>
        </lc:LayoutGroup>

    </lc:LayoutControl>
</UserControl>

#Examples

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:

LabelTemplate_Ex

<UserControl x:Class="LabelTemplate_Ex.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:lc="http://schemas.devexpress.com/winfx/2008/xaml/layoutcontrol"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    <Grid x:Name="LayoutRoot">
        <lc:LayoutControl Orientation="Vertical">
            <lc:LayoutControl.ItemStyle>
                <Style TargetType="lc:LayoutItem">
                    <Setter Property="LabelTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding}"/>
                                    <TextBlock Text=":" Margin="-1,0,0,0"/>
                                </StackPanel>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </lc:LayoutControl.ItemStyle>

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

        </lc:LayoutControl>
    </Grid>
</UserControl>
See Also