Sako73
Sako73

Reputation: 10137

How can I get my custom WPF usercontrol to bind to the content property?

I have the following as a custom user control:

<UserControl x:Class="TestGUI.TBorder">
<Border Style="{StaticResource brdListBoxItem}">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="35" />
            <RowDefinition Height="5" />
            <RowDefinition />
        </Grid.RowDefinitions>

        <TextBlock Grid.Row="0"
                   Grid.Column="0"
                   Style="{StaticResource tblTitleDataStyle}"
                   Text="{Binding Header, Mode=OneWay}" />

        <Rectangle Grid.Row="1"
                   Grid.Column="0"
                   Margin="5,2"
                   Fill="{StaticResource BlueTextBrush}"
                   Height="1"
                   HorizontalAlignment="Stretch" />

        <ContentPresenter Name="ccpMain"
                        Grid.Row="2"
                        Grid.Column="0"
                        Content="{Binding Content}" />
        <!--<TextBlock Grid.Row="2"
                   Text="TEST HERE" />-->
    </Grid>

</Border>

If I comment out the "ContentPresenter", and uncomment the "TextBlock", it appears as expected. If I have it as set, then only thing that displays is whatever is inside of the tags. For example:

<local:TBorder Grid.Row="2"
                        Grid.Column="0" Width="300"
                        Header="The Header">
        <TextBlock Text="astnouhe" />
    </local:TBorder>

displays only the "TextBlock".

Can someone explain this to me?

Thanks for any help.

Upvotes: 0

Views: 856

Answers (1)

Andy
Andy

Reputation: 30418

What did you set the content to? If you are setting it to the XAML that you have in your question, then what it is doing is trying to display the text itself in your control.

You'll need to create another control that uses the XAML in your answer, and set that to the content of your user control in order to display those controls in side the user control.

Upvotes: 1

Related Questions