wpf 点击展开/收缩侧边栏

<Window
    x:Class="Animation.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:Animation"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:system="clr-namespace:System;assembly=mscorlib"
    Title="MainWindow"
    Width="800"
    Height="450"
    mc:Ignorable="d">

    <Window.Resources>

        <Storyboard x:Key="story1">
            <DoubleAnimationUsingKeyFrames
                Storyboard.TargetName="MyAnimatedTranslateTransform"
                Storyboard.TargetProperty="X"
                Duration="0:0:0.5">
                <LinearDoubleKeyFrame KeyTime="0" Value="0" />
                <LinearDoubleKeyFrame KeyTime="0:0:0.25" Value="10" />
                <LinearDoubleKeyFrame KeyTime="0:0:0.5" Value="20" />
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard
            x:Key="story2"
            Storyboard.TargetName="MyAnimatedTranslateTransform"
            Storyboard.TargetProperty="X">
            <DoubleAnimationUsingKeyFrames Duration="0:0:0.5">
                <LinearDoubleKeyFrame KeyTime="0" Value="20" />
                <LinearDoubleKeyFrame KeyTime="50%" Value="10" />
                <LinearDoubleKeyFrame KeyTime="100%" Value="0" />
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

        <!--  定义展开动画  -->
        <Storyboard x:Key="ExpandSidebar">
            <DoubleAnimation
                Storyboard.TargetName="Sidebar"
                Storyboard.TargetProperty="Width"
                To="200"
                Duration="0:0:0.35">
                <DoubleAnimation.EasingFunction>
                    <CubicEase EasingMode="EaseInOut" />
                </DoubleAnimation.EasingFunction>
            </DoubleAnimation>
        </Storyboard>

        <!--  定义收缩动画  -->
        <Storyboard x:Key="CollapseSidebar">
            <DoubleAnimation
                Storyboard.TargetName="Sidebar"
                Storyboard.TargetProperty="Width"
                To="50"
                Duration="0:0:0.35">
                <DoubleAnimation.EasingFunction>
                    <CubicEase EasingMode="EaseInOut" />
                </DoubleAnimation.EasingFunction>
            </DoubleAnimation>
        </Storyboard>
    </Window.Resources>

    <Grid>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Border x:Name="Sidebar" Width="200">

            <!--<ItemsControl VerticalAlignment="Top">
                <system:String>ItemsControl</system:String>
                <system:String>ItemsControl</system:String>
                <system:String>ItemsControl</system:String>
                <system:String>ItemsControl</system:String>
                <system:String>ItemsControl</system:String>
            </ItemsControl>-->


            <StackPanel>
                <Button Height="30" Content="Home" />
                <Button Height="30" Content="Setting" />
                <Button Height="30" Content="Message" />
            </StackPanel>
        </Border>

        <Border
            Grid.Column="1"
            BorderBrush="#999999"
            BorderThickness="1,0,0,0">
            <ToggleButton
                x:Name="ToggleSidebarButton"
                Width="30"
                Height="30"
                Margin="5,0"
                HorizontalAlignment="Left"
                VerticalAlignment="Top"
                IsChecked="True">
                <ToggleButton.Style>
                    <Style TargetType="ToggleButton">
                        <Setter Property="Content" Value="▶" />
                        <Style.Triggers>
                            <Trigger Property="IsChecked" Value="True">
                                <Setter Property="Content" Value="◀" />
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </ToggleButton.Style>
                <ToggleButton.Triggers>
                    <EventTrigger RoutedEvent="ToggleButton.Checked">
                        <BeginStoryboard Storyboard="{StaticResource ExpandSidebar}" />
                    </EventTrigger>

                    <EventTrigger RoutedEvent="ToggleButton.Unchecked">
                        <BeginStoryboard Storyboard="{StaticResource CollapseSidebar}" />
                    </EventTrigger>
                </ToggleButton.Triggers>
            </ToggleButton>
        </Border>

    </Grid>
</Window>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值