6

I want a GridSplitter to be visible only when the user has the mouse over it. For that I'm setting a DataTrigger in its style. But I can't figure out what it's wrong because I don't get the desired behavior. It just stays the same.

                <GridSplitter
            ResizeDirection="Columns"
            ResizeBehavior="BasedOnAlignment"
            Grid.Column="1"
            Grid.Row="0"
            Grid.RowSpan="2"
            Width="8"
            Height="Auto"
            HorizontalAlignment="Left"
            VerticalAlignment="Stretch" 
                Background="AliceBlue"
            Margin="-3 0 0 0">
                <GridSplitter.Style>
                    <Style TargetType="{x:Type GridSplitter}">
                        <Setter Property="Visibility" Value="Hidden"/>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding IsMouseOver}">
                                <Setter Property="Visibility" Value="Visible"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </GridSplitter.Style>
            </GridSplitter>

Do you see something wrong? Does GridSplitter must be styled in a different way?

4

1 回答 1

9

我想通了,必须使用触发器而不是 DataTriggers:

<GridSplitter.Style>
    <Style TargetType="{x:Type GridSplitter}">
        <Setter Property="Background" Value="Transparent"/>
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background" Value="AliceBlue"/>
            </Trigger>
        </Style.Triggers>
    </Style>
</GridSplitter.Style>

顺便说一句,我认为如果我将 设置VisibilityHidden我无法定位GridSplitter,所以我改为切换它Background

于 2013-09-05T13:30:11.570 回答