Binding in Label.ContentTemplate

Set the Content property on the Label to the current DataContext:

<Label HorizontalAlignment="Center" Content="{Binding}">

or, set the StackPanel as the Content and don't use a template at all:

<Label HorizontalAlignment="Center">
    <StackPanel Orientation="Horizontal" Width="100">
        <TextBlock Text="{Binding RecordCount}"/>
        <TextBlock Text=" Cars"/>
    </StackPanel>
</Label>

The ContentTemplate is used to present the Content. Since it is null, the DataContext is null when your template is instantiated. The TextBlocks are still created, so Cars is rendered, but null doesn't have a RecordCount property so the first text block is rendered with no text.

Also, if you are only using two TextBlocks to concatenate text, you can use the StringFormat property in .NET 3.5 SP1 or later:

<Label Content="{Binding RecordCount}" ContentStringFormat="{}{0} Cars"/>

Tags:

Wpf

Binding

Mvvm