我在主页上有一个tabcontrol。我想向选项卡标题模板添加关闭按钮。如何在C#代码中将标题模板添加到tabitems。请帮忙..
最佳答案
参见:在UserControl的资源中键入此代码
<Style TargetType='sdk:TabItem'>
<Setter Property='HeaderTemplate'>
<Setter.Value>
<DataTemplate>
<StackPanel Orientation='Horizontal'
Background='Transparent'>
<TextBlock Text='{Binding}' />
<!--<Button Command="{Binding RemoveItemCommand}" VerticalAlignment='Center'
Style="{StaticResource CloseButton}"
Margin="5,0,0,0"
Content="M0,0 L6,6 M6, 0 L0,6"
ToolTipService.ToolTip="Remove item" />-->
<Button x:Name='btnCloaseTab'
Click='btnCloaseTab_Click'
VerticalAlignment='Center'
Style="{StaticResource CloseButton}"
Margin="5,0,0,0"
Content="M0,0 L6,6 M6, 0 L0,6"
ToolTipService.ToolTip="بستن زبانه" />
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
关于silverlight-4.0 - 如何以编程方式为TabControl创建HeaderTemplate?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4132232/