如何向ContentPane的标题添加关闭按钮

时间:2009-06-29 12:12:30

标签: wpf button

如何在ContentPane的标题中添加关闭按钮?请用一个例子解释一下。

2 个答案:

答案 0 :(得分:1)

<DataTemplate x:Key="tabItemHeaderWithClose">
    <DockPanel x:Name="pnl">
        <Button x:Name="closeBtn" DockPanel.Dock="Right"
                Visibility="Collapsed" 
                Margin="3,3,0,3" Width="14" VerticalAlignment="Top"
                Command="{x:Static DockManager:ContentPaneCommands.Close}"
                CommandTarget="{Binding Path=Pane,RelativeSource={RelativeSource AncestorType={x:Type DockManager:PaneTabItem}}}"
                Style="{DynamicResource {x:Static DockManager:TabGroupPane.DocumentCloseButtonStyleKey}}" />
        <TextBlock Text="{Binding}" />
    </DockPanel>
    <DataTemplate.Triggers>
        <Trigger Property="DockManager:XamDockManager.PaneLocation"
                 Value="Document">
            <Setter TargetName="closeBtn" Property="Visibility" Value="Visible"/>
        </Trigger>
    </DataTemplate.Triggers>
</DataTemplate>

答案 1 :(得分:0)

XAML:

    <ContentControl Name="contentControl1" >
        <StackPanel>
            <StackPanel Name="headerPanel" VerticalAlignment="Top" >
                <Grid>
                    <Label>Header text</Label>
                    <Button Name="closeButton" Height="20" Width="20" HorizontalAlignment="Right" Click="closeButton_Click">X</Button>
                </Grid>
            </StackPanel>
            <StackPanel Name="contentPanel" VerticalAlignment="Stretch" >
                <Label>Hello</Label>
            </StackPanel>
        </StackPanel>
    </ContentControl>

C#:

    private void closeButton_Click(object sender, RoutedEventArgs e)
    {
        contentControl1.Visibility = Visibility.Hidden;
    }