隐藏 WPF StackPanel(非扩展器)时出现问题

发布于 2024-12-13 10:54:29 字数 370 浏览 0 评论 0原文

我在 WPF StackPanel 方面遇到了真正的麻烦 - 我需要使其动画化,不仅可以水平滚动其内容(这或多或少是可以的),而且我还必须使其展开/折叠(动画)通过按包含窗口上的某个按钮。

我尝试过很多动画扩展器控件(例如 http://www.codeproject.com /KB/WPF/AnimatingExpander.aspx),但它们的功能已超载(以及一些包含控件的工件),不适合我的任务。

所以问题是如何使简单的水平方向的 StackPanel 通过单击按钮以动画方式展开/折叠?

I have a real trouble with WPF StackPanel - I need to make it animated not only for scrolling its content horizontaly (this is ok more or less), but also I must make it expand/collapse (animated) by pressing some button on the containing window.

I have tried a lot of animated expander controls (for example http://www.codeproject.com/KB/WPF/AnimatingExpander.aspx) but they have overloaded with functionality (and some artifacts with contained controls) and not suitable for my task.

So the question is how to make SIMPLE horizontal oriented StackPanel to expand/collapse with animation by button click?

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

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

发布评论

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

评论(2

在风中等你 2024-12-20 10:54:29

最简单的方法是在 ToggleButton.Checked.Unchecked 事件上启动动画:

<StackPanel x:Name="MyStackPanel">...</StackPanel>

...

<ToggleButton Content="Click Me">
    <ToggleButton.Triggers>
        <EventTrigger RoutedEvent="ToggleButton.Checked">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation Storyboard.TargetName="MyStackPanel" 
                                     Storyboard.TargetProperty="Width"
                                     To="0"
                                     Duration="0:0:0.5" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
        <EventTrigger RoutedEvent="ToggleButton.Unchecked">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation Storyboard.TargetName="MyStackPanel" 
                                     Storyboard.TargetProperty="Width"
                                     To="200"
                                     Duration="0:0:0.5" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </ToggleButton.Triggers>
</ToggleButton>

The simplest approach is to start an animation on a ToggleButton.Checked or .Unchecked event:

<StackPanel x:Name="MyStackPanel">...</StackPanel>

...

<ToggleButton Content="Click Me">
    <ToggleButton.Triggers>
        <EventTrigger RoutedEvent="ToggleButton.Checked">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation Storyboard.TargetName="MyStackPanel" 
                                     Storyboard.TargetProperty="Width"
                                     To="0"
                                     Duration="0:0:0.5" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
        <EventTrigger RoutedEvent="ToggleButton.Unchecked">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation Storyboard.TargetName="MyStackPanel" 
                                     Storyboard.TargetProperty="Width"
                                     To="200"
                                     Duration="0:0:0.5" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </ToggleButton.Triggers>
</ToggleButton>
黒涩兲箜 2024-12-20 10:54:29

为什么不为堆栈面板的宽度添加故事板和双动画。通过单击按钮,您可以通过代码或定义事件触发器来启动动画。

Why not adding a storyboard and double animation for stackpanel's width. By clicking the button you can start the animation in code or by defining event triggers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文