如何显示/隐藏面板

发布于 2024-09-10 09:27:58 字数 72 浏览 4 评论 0原文

当鼠标悬停时,面板将显示在左侧,离开鼠标时面板将隐藏。

在 WPF 中如何做到这一点?

有组件吗?

When the mouse hover, the panel will be show on the left side and leave the mouse it will be hiden.

How to do that in WPF?

Is there any component?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心安伴我暖 2024-09-17 09:27:58

这是我的一个应用程序中的滑出式控制台面板(我没有包含样式,但您明白了)。它以零宽度和高度开始,并在单击切换按钮时展开(请注意将滑出动画与切换按钮的 Unchecked 事件相关联的 EventTrigger)。
如果您将其基于鼠标悬停事件,那应该会帮助您。

           <!-- Console Panel -->
        <Border Style="{StaticResource SettingsWindowStyle}" x:Name="ConsoleBorder" Grid.Row="0" Grid.Column="2" Margin="0,0,0,0">
            <Border.Triggers>
                <EventTrigger SourceName="toggleConsole"  RoutedEvent="ToggleButton.Checked">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Duration="0:0:0.2" Storyboard.TargetProperty="Width" To="635" />
                            <DoubleAnimationUsingKeyFrames BeginTime="0:0:0.2" Duration="0:0:0.3" Storyboard.TargetProperty="Height">
                                <LinearDoubleKeyFrame Value="680" KeyTime="0:0:0.2" />
                                <LinearDoubleKeyFrame Value="690" KeyTime="0:0:0.24" />
                                <LinearDoubleKeyFrame x:Name="FullScreenConsole" Value="700" KeyTime="0:0:0.3" />
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
                <EventTrigger SourceName="toggleConsole" RoutedEvent="ToggleButton.Unchecked">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimationUsingKeyFrames Duration="0:0:0.2" Storyboard.TargetProperty="Height">
                                <LinearDoubleKeyFrame Value="100" KeyTime="0:0:0.2" />
                            </DoubleAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames BeginTime="0:0:0.2" Duration="0:0:0.2" Storyboard.TargetProperty="Width">
                                <LinearDoubleKeyFrame Value="40" KeyTime="0:0:0.2" />
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Border.Triggers>
            <Grid Margin="10">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="10*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="20" />
                </Grid.ColumnDefinitions>
                <ToggleButton Style="{StaticResource ToggleButtonStyle}" x:Name="toggleConsole">
                    <TextBlock Text="Console" Foreground="Black">
                                <TextBlock.LayoutTransform>
                                    <RotateTransform Angle="90" />
                                </TextBlock.LayoutTransform>
                    </TextBlock>
                    <ToggleButton.ToolTip>
                        <ToolTip>
                            <TextBlock Padding="10" Background="White" Foreground="Black" Text="Show/Hide" />
                        </ToolTip>
                    </ToggleButton.ToolTip>
                </ToggleButton>
                <Rectangle Style="{StaticResource RectangleDividerStyle}" />
                <DockPanel Grid.Column="0" Margin="10,2,0,2" Background="#33FFFFFF">
                    <StackPanel Orientation="Vertical" DockPanel.Dock="Top" Margin="0,10,0,0">
                        <!-- main screen box -->
                        <TextBox x:Name="txtConsole" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True"  Margin="5,0,0,0" Width="500" Height="590" HorizontalAlignment="Left" VerticalAlignment="Top"></TextBox>
                        <!-- button row -->
                        <StackPanel Orientation="Horizontal" Grid.Row="1" Margin="5,10,0,0">
                            <TextBox x:Name="txtSend" Width="400" Height="30" Margin="0,0,0,0" KeyDown="txtSend_KeyDown" >
                            </TextBox>
                            <Button Name="cmdSend" Click="cmdSend_Click" Width="80" Margin="3,0,0,0" Template="{StaticResource GlassButton}">
                                <TextBlock Foreground="LightGray">Send</TextBlock>
                            </Button>
                         </StackPanel>
                            <StackPanel Orientation="Horizontal" Grid.Row="1" Margin="5,5,0,0">
                                <Button HorizontalAlignment="Left" Margin="5,2,0,0" Foreground="White" Height="30" x:Name="btnRawStatus" Click="btnRawStatus_Click" Width="100"  Template="{StaticResource GlassButton}">Raw Status</Button>
                                <Button HorizontalAlignment="Left" Margin="5,2,0,0" Foreground="White" Height="30" x:Name="btnLast50" Click="btnLast50_Click"  Width="100"  Template="{StaticResource GlassButton}">Last 50 Logs</Button>
                            </StackPanel>
                        </StackPanel>
                </DockPanel>
                </Grid>
        </Border>

Here's a slide-out console panel from one of my apps (I haven't included the style, but you get the idea). It starts with a width and height of zero, and expands when a toggle button is clicked (notice the EventTrigger that ties the slide-out animation to the Unchecked event of the Togglebutton).
If you base it on the mouseover event instead, that should help you on your way.

           <!-- Console Panel -->
        <Border Style="{StaticResource SettingsWindowStyle}" x:Name="ConsoleBorder" Grid.Row="0" Grid.Column="2" Margin="0,0,0,0">
            <Border.Triggers>
                <EventTrigger SourceName="toggleConsole"  RoutedEvent="ToggleButton.Checked">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Duration="0:0:0.2" Storyboard.TargetProperty="Width" To="635" />
                            <DoubleAnimationUsingKeyFrames BeginTime="0:0:0.2" Duration="0:0:0.3" Storyboard.TargetProperty="Height">
                                <LinearDoubleKeyFrame Value="680" KeyTime="0:0:0.2" />
                                <LinearDoubleKeyFrame Value="690" KeyTime="0:0:0.24" />
                                <LinearDoubleKeyFrame x:Name="FullScreenConsole" Value="700" KeyTime="0:0:0.3" />
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
                <EventTrigger SourceName="toggleConsole" RoutedEvent="ToggleButton.Unchecked">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimationUsingKeyFrames Duration="0:0:0.2" Storyboard.TargetProperty="Height">
                                <LinearDoubleKeyFrame Value="100" KeyTime="0:0:0.2" />
                            </DoubleAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames BeginTime="0:0:0.2" Duration="0:0:0.2" Storyboard.TargetProperty="Width">
                                <LinearDoubleKeyFrame Value="40" KeyTime="0:0:0.2" />
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Border.Triggers>
            <Grid Margin="10">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="10*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="20" />
                </Grid.ColumnDefinitions>
                <ToggleButton Style="{StaticResource ToggleButtonStyle}" x:Name="toggleConsole">
                    <TextBlock Text="Console" Foreground="Black">
                                <TextBlock.LayoutTransform>
                                    <RotateTransform Angle="90" />
                                </TextBlock.LayoutTransform>
                    </TextBlock>
                    <ToggleButton.ToolTip>
                        <ToolTip>
                            <TextBlock Padding="10" Background="White" Foreground="Black" Text="Show/Hide" />
                        </ToolTip>
                    </ToggleButton.ToolTip>
                </ToggleButton>
                <Rectangle Style="{StaticResource RectangleDividerStyle}" />
                <DockPanel Grid.Column="0" Margin="10,2,0,2" Background="#33FFFFFF">
                    <StackPanel Orientation="Vertical" DockPanel.Dock="Top" Margin="0,10,0,0">
                        <!-- main screen box -->
                        <TextBox x:Name="txtConsole" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True"  Margin="5,0,0,0" Width="500" Height="590" HorizontalAlignment="Left" VerticalAlignment="Top"></TextBox>
                        <!-- button row -->
                        <StackPanel Orientation="Horizontal" Grid.Row="1" Margin="5,10,0,0">
                            <TextBox x:Name="txtSend" Width="400" Height="30" Margin="0,0,0,0" KeyDown="txtSend_KeyDown" >
                            </TextBox>
                            <Button Name="cmdSend" Click="cmdSend_Click" Width="80" Margin="3,0,0,0" Template="{StaticResource GlassButton}">
                                <TextBlock Foreground="LightGray">Send</TextBlock>
                            </Button>
                         </StackPanel>
                            <StackPanel Orientation="Horizontal" Grid.Row="1" Margin="5,5,0,0">
                                <Button HorizontalAlignment="Left" Margin="5,2,0,0" Foreground="White" Height="30" x:Name="btnRawStatus" Click="btnRawStatus_Click" Width="100"  Template="{StaticResource GlassButton}">Raw Status</Button>
                                <Button HorizontalAlignment="Left" Margin="5,2,0,0" Foreground="White" Height="30" x:Name="btnLast50" Click="btnLast50_Click"  Width="100"  Template="{StaticResource GlassButton}">Last 50 Logs</Button>
                            </StackPanel>
                        </StackPanel>
                </DockPanel>
                </Grid>
        </Border>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文