MouseOver上的Gridsplitter visibile

时间:2013-09-05 13:16:08

标签: c# wpf gridsplitter

我希望只有当用户将鼠标移到它上面时才能看到GridSplitter。为此,我设置了DataTrigger的风格。但我无法弄清楚它是什么错,因为我没有得到理想的行为。它保持不变。

                <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>

你看错了吗? GridSplitter必须以不同的方式设置样式吗?

1 个答案:

答案 0 :(得分:8)

我想通了,必须使用Triggers而不是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>

顺便说一句,我认为如果我将Visibility设置为Hidden我无法定位GridSplitter,那么我会切换其Background