簡體   English   中英

XAML中的事件處理

[英]Event handling in xaml

我已經為TabItem修改了ControlTemplate ,使其具有一個用於標簽的關閉按鈕。 以下是我的XAML:

<ControlTemplate x:Key="TabItemControlTemplate" TargetType="{x:Type TabItem}">
    <Border BorderThickness="1" BorderBrush="DarkGray" CornerRadius="0,4,0,0">
        <Grid Name="Panel">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="0.7*" />
                <ColumnDefinition Width="0.3*" />
            </Grid.ColumnDefinitions>

            <ContentPresenter x:Name="ContentSite" VerticalAlignment="Center" HorizontalAlignment="Center" ContentSource="Header" Margin="10,2" />
            <Button x:Name="closeButton" Background="Transparent"  Grid.Column="1" Click="Button_Click" Width="15" Height="15" BorderThickness="0" Margin="0,0,2,0">
                <Button.Template>
                    <ControlTemplate TargetType="Button">
                        <Grid Background="Transparent">
                            <Ellipse x:Name="backgroundEllipse" />
                            <Path x:Name="ButtonPath" Margin="3" Stroke="{StaticResource NormalForegroundBrush}" StrokeThickness="1.5" StrokeStartLineCap="Square" StrokeEndLineCap="Square" Stretch="Uniform" VerticalAlignment="Center" HorizontalAlignment="Center">
                                <Path.Data>
                                    <PathGeometry>
                                        <PathGeometry.Figures>
                                            <PathFigure StartPoint="0,0">
                                                <LineSegment Point="25,25" />
                                            </PathFigure>
                                            <PathFigure StartPoint="0,25">
                                                <LineSegment Point="25,0" />
                                            </PathFigure>
                                        </PathGeometry.Figures>
                                    </PathGeometry>
                                </Path.Data>
                            </Path>
                        </Grid>

                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="backgroundEllipse" Property="Fill"  Value="{StaticResource HoverBackgroundBrush}" />
                                <Setter TargetName="ButtonPath" Property="Stroke" Value="{StaticResource HoverForegroundBrush}" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Button.Template>
            </Button>
        </Grid>
    </Border>
    <ControlTemplate.Triggers>
        <Trigger Property="IsSelected" Value="True">
            <Setter TargetName="Panel" Property="Background" Value="SkyBlue" />
        </Trigger>
        <Trigger Property="IsSelected" Value="False">
            <Setter TargetName="Panel" Property="Background" Value="White" />
        </Trigger>
        <Trigger Property="IsEnabled" Value="false">
            <Setter Property="Visibility" Value="Collapsed" />
        </Trigger>
    </ControlTemplate.Triggers>
</ControlTemplate>

在上面的ControlTemplate ,我想處理XAML本身中的click事件,即,單擊該選項卡時將其隱藏。 我該如何實現?

您可以使用切換按鈕而不是按鈕作為關閉按鈕,然后在選中的觸發器上將Tabitem可見性設置為隱藏/折疊。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM