WPF滑动网格

时间:2013-11-23 13:16:13

标签: c# wpf xaml

我有一个包含功能区菜单的WPF应用程序。这很简单,因为我正在尝试更多地了解WPF。所以我有两个功能区组。每组都有一个按钮。当有人将鼠标悬停在按钮上以便网格向下滑动时,我想要发生什么。即从功能区菜单下方开始,一直到窗口底部。

以下是我的代码。它有点工作。当它悬停在按钮“buttSimSec”上时,网格“paneSimFirst”会滑动。但是它从我的应用程序窗口的中心开始。当鼠标悬停在其上时,另一个按钮不起作用。

此外,我想知道如何不必为我的功能区中的每个按钮重复EventTrigger代码?

<DockPanel Name="dockMain">
    <Ribbon DockPanel.Dock="Top" Title="Simulator" x:Name="mainRibbon">            
        <RibbonTab x:Name="Simulator" Header="Simulator">
            <RibbonGroup x:Name="grpSecurities" Header="Securities">
                <RibbonButton x:Name="buttSimSec" Label="Select Securities">
                    <RibbonButton.Triggers>
                        <EventTrigger RoutedEvent="MouseEnter">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation
                                        Storyboard.TargetName="paneSimFirst"
                                        Storyboard.TargetProperty="(Grid.Height)"
                                        From="0"
                                        To="50"
                                        Duration="0:0:2"/>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </RibbonButton.Triggers>
                </RibbonButton>
            </RibbonGroup>
            <RibbonGroup x:Name="grpModels" Header="Models">
                <RibbonButton x:Name="buttModels" Label="View Models">
                    <RibbonButton.Triggers>
                        <EventTrigger RoutedEvent="MouseEnter">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation
                                        Storyboard.TargetName="paneSimSecond"
                                        Storyboard.TargetProperty="(Grid.Height)"
                                        From="0"
                                        To="50"
                                        Duration="0:0:2"/>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </RibbonButton.Triggers>
                </RibbonButton>
            </RibbonGroup>
        </RibbonTab>
    </Ribbon>
    <Grid Name="ParentGrid" Grid.IsSharedSizeScope="True" Visibility="Visible">
        <Grid x:Name="paneSimFirst" Visibility="Visible" Background="Purple">
        </Grid>
        <Grid x:Name="paneSimSecond" Visibility="Collapsed" Background="YellowGreen">
        </Grid>
    </Grid>
</DockPanel>

1 个答案:

答案 0 :(得分:0)