0

我的要求是有一个 2 行的网格 - 第一行将填充组合框作为数据库查询的搜索条件。第二行将是带有结果的 DataGrid。

当我将鼠标悬停在上方时,我希望上部网格从顶部向下滑动,并在鼠标离开时向上滑动。我想我可以在“过滤器”顶部有一个简单的文本块,并将鼠标悬停在它上面会拉下组合框?

我有这样的东西,但是当鼠标悬停时,动画会不停地上升/下降。

    <Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="40"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <Grid Grid.Row="0">
        <Grid.Triggers>
            <EventTrigger RoutedEvent="MouseEnter">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation 
                    Storyboard.TargetName="ControlsGrid" 
                    Storyboard.TargetProperty="(Grid.Height)"
                    From="0" 
                    To="66" 
                    Duration="0:0:0.5" />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
            <EventTrigger RoutedEvent="MouseLeave">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation 
                    Storyboard.TargetName="ControlsGrid"
                    Storyboard.TargetProperty="(Grid.Height)"
                    From="66" 
                    To="0" 
                    Duration="0:0:0.5" />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Grid.Triggers>

        <TextBlock HorizontalAlignment="Center" FontSize="20" Text="Filters..."/>
    </Grid>

    <Grid Margin="0" Name="ControlsGrid" VerticalAlignment="top" Background="Yellow"/>
    <DataGrid Grid.Row="1" ColumnHeaderStyle="{DynamicResource GridViewColumnHeaderStyle}" Background="LightGray" RowBackground="LightYellow" AlternatingRowBackground="LightBlue" 
              x:Name="dataGridViewRoomQuery"  BorderBrush="Gray" BorderThickness="5"/>

</Grid>
4

1 回答 1

0

您的方法的问题在于,只要将“悬停”网格(带有事件触发器的网格)放在它上面,它MouseLeave就会收到一个事件。ControlsGrid

您必须将其ControlsGrid放入悬停网格中:

<Grid Grid.Row="0" Background="Transparent">
    <Grid.Triggers>
        <EventTrigger RoutedEvent="MouseEnter">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation Storyboard.TargetName="ControlsGrid" 
                                        Storyboard.TargetProperty="Height"
                                        To="66" Duration="0:0:0.5" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
        <EventTrigger RoutedEvent="MouseLeave">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation Storyboard.TargetName="ControlsGrid" 
                                        Storyboard.TargetProperty="Height"
                                        To="0" Duration="0:0:0.5" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Grid.Triggers>

    <TextBlock HorizontalAlignment="Center" FontSize="20" Text="Filters..."/>

    <Grid Name="ControlsGrid" Height="0" VerticalAlignment="Top" Background="Yellow">
    </Grid>
</Grid>
<DataGrid .../>
于 2013-04-08T06:25:10.057 回答