Jak mogę ustawić tekst etykiety

Wcześniej uzyskałem usercontrol, który chcę umieścić w FixedDocument, ale zanim to zrobię, muszę zmienić tekst etykiety. Myślę, że muszę użyć właściwości zależności.

Oto uproszczony XAML.

<UserControl x:Class="PrinterTest.TestControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
             DataContext="{Binding RelativeSource={RelativeSource Self}}">
    <Grid>
        <Label Content="{Binding LabelCaption}"
               Height="24" HorizontalContentAlignment="Right" Name="lblCaption"     
               Width="140" />
    </Grid>
</UserControl>

I powiązanie z kodem

public partial class TestControl : UserControl
{
    public TestControl()
    {
        InitializeComponent();
    }

    public readonly static DependencyProperty 
        LabelCaptionDP = DependencyProperty.Register("LabelCaption",
                                                     typeof(string), 
                                                     typeof(TestControl),
                                                     new FrameworkPropertyMetadata("no data"));

    public string LabelCaption
    {
        get { return (string)GetValue(LabelCaptionDP); }
        set { SetValue(LabelCaptionDP, value); }
    }

W bitach wywołujących tworzę instancję przezTestControl myControl = new TestControl();

Co robię źle, ponieważ nie mogę uzyskać dostępu do właściwości w nowej kopii kontrolki? Dziękuję Ci!

questionAnswers(1)

yourAnswerToTheQuestion