HeaderedContentControl.Header 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置用于每个控件的标头的数据。
public:
property System::Object ^ Header { System::Object ^ get(); void set(System::Object ^ value); };
[System.ComponentModel.Bindable(true)]
[System.Windows.Localizability(System.Windows.LocalizationCategory.Label)]
public object Header { get; set; }
[<System.ComponentModel.Bindable(true)>]
[<System.Windows.Localizability(System.Windows.LocalizationCategory.Label)>]
member this.Header : obj with get, set
Public Property Header As Object
属性值
标头对象。 默认值为 null。
- 属性
示例
以下示例创建一个包含两TabItem个TabControl从中继承的对象HeaderedContentControl。 第一个TabItem对象包含对象作为内容,Header并且 ContentHeader :设置为包含 a Ellipse 和 a ContentTextBlockStackPanel; 设置为包含 a 和 a ; 设置为StackPanel包含 a TextBlock 和 a Label的对象。UIElement 第 Header 二 TabItem 个字符串设置为字符串, Content 并且设置为单个 TextBlock字符串。
<TabControl>
<TabItem>
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<Ellipse Width="10" Height="10" Fill="DarkGray"/>
<TextBlock>Tab 1</TextBlock>
</StackPanel>
</TabItem.Header>
<StackPanel>
<TextBlock>Enter some text</TextBlock>
<TextBox Name="textBox1" Width="50"/>
</StackPanel>
</TabItem>
<TabItem Header="Tab 2">
<!--Bind TextBlock.Text to the TextBox on the first
TabItem.-->
<TextBlock Text="{Binding ElementName=textBox1, Path=Text}"/>
</TabItem>
</TabControl>
下图显示了 TabControl 上一个示例创建的。
Header 属性中具有不同类型的 TabControl
以下示例创建两个
<Style TargetType="HeaderedContentControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type HeaderedContentControl}">
<StackPanel>
<Grid>
<Rectangle Stroke="{TemplateBinding Background}"/>
<ContentPresenter ContentSource="Header"/>
</Grid>
<Grid>
<Rectangle Fill="{TemplateBinding Background}"/>
<ContentPresenter ContentSource="Content"/>
</Grid>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<DataTemplate x:Key="titleText">
<TextBlock Text="{Binding}"
Foreground="Green"
FontSize="16"
FontWeight="Normal"
FontStyle="Italic"
TextWrapping="Wrap"/>
</DataTemplate>
<DataTemplate x:Key="contentText">
<TextBlock Text="{Binding}"
Foreground="Brown"
FontSize="12"
FontWeight="Normal"
FontFamily="Arial Narrow"
TextWrapping="Wrap"/>
</DataTemplate>
<HeaderedContentControl Name="hcontCtrl" Background="Beige"
HeaderTemplate="{StaticResource titleText}"
ContentTemplate="{StaticResource contentText}"
Header="This is the header."
Content="This is the content."/>
注解
与 Content 属性一 ContentControl样, Header 可以是任何类型的。 该 HeaderedContentControl 逻辑使用相同的逻辑来显示 Header 上述 ContentControl.Content逻辑。
Dependency 属性信息
| 物品 | 价值 |
|---|---|
| 标识符字段 | HeaderProperty |
元数据属性设置为 true |
没有 |