2010-05-30 69 views
1

我想写的二手这样的自定义控件:WPF:自定义控制结合其内容的标签

<HorizontalTick>Some string</HorizontalTick> 

它应该呈现这样的:

- 一些字符串--- ----------------------------------------

这里是我的代码:

<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> 

它的工作除外为标签绑定。有人可以帮我填写问号吗?我想过使用ContentPresenter,但似乎内联绑定是最好的。

-Neal

回答

1

的结合将是:

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

然而,重新使用ContentPresenter能够显示任何内容,而不是直接补充说,将使用自己的ContentPresenter来显示它的标签。

也就是说,你也可以用一个简单的ContentControl替换你的整个控件,用ContentTemplate来显示线条和内部内容。