WPF: Custom control that binds its content to a label

Posted by nialsh on Stack Overflow See other posts from Stack Overflow or by nialsh
Published on 2010-05-30T20:01:01Z Indexed on 2010/05/30 20:02 UTC
Read the original article Hit count: 194

Filed under:

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>

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

© Stack Overflow or respective owner

Related posts about wpf-controls