tags:

views:

16

answers:

1

I want to write a custom control that's used like this:

<HorizontalTick>Some string</HorizontalTick>

It should render like this:

-- Some string -------------------------------------------

Here's my code:

<UserControl x:Class="WeatherDownloadDisplay.View.HorizontalTick"
             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:DesignWidth="348"
             Name="controlRoot">
    <DockPanel LastChildFill="True">
        <UserControl VerticalAlignment="Center" BorderBrush="Black" BorderThickness="1" Width="10"/>
        <Label Content="???" />
        <UserControl VerticalAlignment="Center" BorderBrush="Black" BorderThickness="1"/>
    </DockPanel>
</UserControl>

It works except for the label binding. Can someone help me fill in the question marks? I thought about using a ContentPresenter but it seems like an inline binding would be best.

-Neal

+1  A: 

The binding would be:

<Label Content="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=Content}" />

However, reconsider using a ContentPresenter to be able to show any content directly rather than adding a label that will use its own ContentPresenter to show it.

That being said, you could also replace your whole control by a simple ContentControl with a ContentTemplate showing the lines and the inner content.

Julien Lebosquain