zoukankan      html  css  js  c++  java
  • 使用ToggleButton和StackPanel+Border实现圆角开关按钮动画效果

    <ToggleButton  Height="40"  Width="105" HorizontalAlignment="Left" Margin="138,122,0,0" Name="button1" VerticalAlignment="Top" Click="button1_Click">
                <ToggleButton.Content>
                    <StackPanel Name="s1" Width="100" Height="22" Orientation="Horizontal" HorizontalAlignment="Left">
                        <Border Name="cd1" CornerRadius="10" BorderThickness="1" Width="100" BorderBrush="#FF001900">
                            <Border.Background>
                                <ImageBrush ImageSource="/MoveButton;component/Images/12.png" />
                            </Border.Background>
                        </Border>
                        <Border Name="cd2" CornerRadius="10" BorderThickness="1" Width="100" BorderBrush="#FF001900">
                            <Border.Background>
                                <ImageBrush ImageSource="/MoveButton;component/Images/13.png" />
                            </Border.Background>
                        </Border>
                    </StackPanel>
                </ToggleButton.Content>
            </ToggleButton>
            private void button1_Click(object sender, RoutedEventArgs e)
            {
                if (button1.IsChecked == true)
                {
                    DoubleAnimation d1 = new DoubleAnimation();
                    d1.From = 0;
                    d1.To = 100;
                    d1.Duration = new Duration(TimeSpan.Parse("0:0:0.2"));
                    cd2.BeginAnimation(StackPanel.WidthProperty, d1);
    
                    DoubleAnimation d2 = new DoubleAnimation();
                    d2.From = 100;
                    d2.To = 0;
                    d2.Duration = new Duration(TimeSpan.Parse("0:0:0.2"));
                    cd1.BeginAnimation(StackPanel.WidthProperty, d2);
                }
    
                if (button1.IsChecked == false)
                {
                    DoubleAnimation d1 = new DoubleAnimation();
                    d1.From = 100;
                    d1.To = 0;
                    d1.Duration = new Duration(TimeSpan.Parse("0:0:0.2"));
                    cd2.BeginAnimation(StackPanel.WidthProperty, d1);
    
                    DoubleAnimation d2 = new DoubleAnimation();
                    d2.From = 0;
                    d2.To = 100;
                    d2.Duration = new Duration(TimeSpan.Parse("0:0:0.2"));
                    cd1.BeginAnimation(StackPanel.WidthProperty, d2);
                }
            }

    代码没精简,无图无真相,看看OFF和ON

  • 相关阅读:
    postgresql修改postgres用户密码
    centos7 安装netstat命令工具
    sqlplus、lsnrctl命令工具不可用(libclntsh.so.11.1)
    oracle修改数据文件目录
    oracle数据库主主复制
    Spring--quartzJob配置
    TimerTask--spring配置
    SSM+Apache shiro--ehcache缓存清理
    SSM+Apache shiro--自定义realm
    ssm+Apache shiro--配置文件
  • 原文地址:https://www.cnblogs.com/Events/p/3342447.html
Copyright © 2011-2022 走看看