M
M
Mikhail Usotsky2017-01-20 16:44:11
WPF
Mikhail Usotsky, 2017-01-20 16:44:11

How to bind the data of the Label element?

I'm trying to pass Text data from Content to a TextBlock in a ControlTemplate. But something doesn't work. What did I miss here?

<Style TargetType="{x:Type Label}" x:Key="Label2">
        <Setter Property="Content" Value="{Binding Text}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <Border Margin="2"
                        HorizontalAlignment="Left"
                        Background="DarkCyan"
                        BorderBrush="LightCyan"
                        BorderThickness="1"
                        CornerRadius="3">
                        <TextBlock Margin="0"
                               Padding="5"
                               FontSize="13"
                               FontWeight="Medium"
                               Foreground="LightCyan"
                               Text="{Binding Text}"
                               TextAlignment="Center"/>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2017-01-21
@AquariusStar

The template must use a TemplateBinding. Text="{TemplateBindingText}"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question