zoukankan      html  css  js  c++  java
  • 潜移默化学会WPFBorder,焦点移动

       private TextBox tb;
            public MainWindow()
            {
                InitializeComponent();
            }
    
            private void TextBox_LostFocus(object sender, RoutedEventArgs e)
            {
                tb = (TextBox)sender;
    
                DoubleAnimation ta = new DoubleAnimation();
                ta.From = 0.5;
                ta.To = 0;
                ta.Duration = new Duration(TimeSpan.FromMilliseconds(100));
                Storyboard.SetTargetName(ta, "Opacity");
                Storyboard.SetTargetProperty(ta, new PropertyPath(Border.OpacityProperty));
                Storyboard storyBoard = new Storyboard();
                storyBoard.Children.Add(ta);
                this.RegisterName("Opacity", this.ColorFulBorder);
                storyBoard.Begin(this, true);
                
            }
    
            private void TextBox_GotFocus(object sender, RoutedEventArgs e)
            {
    
                double fleft, ftop, fwidth;
                TextBox ntb = (TextBox)sender;
                if (tb == null)
                {
                    fleft = ntb.Margin.Left;
                    ftop = ntb.Margin.Top;
                    fwidth = ntb.Width;
                }
                else
                {
                    //获得失去焦点的文本框的位置
                    fleft = tb.Margin.Left;
                    ftop = tb.Margin.Top;
                    fwidth = tb.Width;
    
                }
                //获得获得焦点的文本框的位置
                double nleft = ntb.Margin.Left;
                double ntop = ntb.Margin.Top;
                double nwidth = ntb.Width;
                //开启动画效果
                
                //ThicknessAnimation ta = new ThicknessAnimation();
                SplineThicknessKeyFrame stk1 = new SplineThicknessKeyFrame();
                SplineThicknessKeyFrame stk2 = new SplineThicknessKeyFrame();
                ThicknessAnimationUsingKeyFrames du = new ThicknessAnimationUsingKeyFrames();
                
    
                stk1.Value = new Thickness(fleft, ftop, 0, 0);
                stk2.Value = new Thickness(nleft, ntop, 0, 0);
    
                stk1.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0));
                stk2.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(400));
                stk2.KeySpline = new KeySpline(0, 0, 0, 1);
    
                du.KeyFrames.Add(stk1);
                du.KeyFrames.Add(stk2);
    
                //ta.From = new Thickness(fleft,ftop,0,0);
                //ta.To = new Thickness(nleft, ntop, 0, 0);
                //ta.Duration = new Duration(TimeSpan.FromMilliseconds(200));
    
    
    
                Storyboard.SetTargetName(du, "Margin");
                Storyboard.SetTargetProperty(du, new PropertyPath(Border.MarginProperty));
    
                Storyboard storyBoard = new Storyboard();
    
                storyBoard.Children.Add(du);
    
                this.RegisterName("Margin", this.ColorFulBorder);
    
    
                DoubleAnimation ta = new DoubleAnimation();
                ta.From = 0;
                ta.To = 0.5;
                ta.Duration = new Duration(TimeSpan.FromMilliseconds(100));
                Storyboard.SetTargetName(ta, "Opacity");
                Storyboard.SetTargetProperty(ta, new PropertyPath(Border.OpacityProperty));
                Storyboard storyBoard2 = new Storyboard();
                storyBoard2.Children.Add(ta);
                this.RegisterName("Opacity", this.ColorFulBorder);
                storyBoard2.Begin(this, true);
    
    
                DoubleAnimation tw = new DoubleAnimation();
                tw.From = fwidth;
                tw.To = nwidth;
                tw.Duration = new Duration(TimeSpan.FromMilliseconds(100));
                Storyboard.SetTargetName(tw, "Width");
                Storyboard.SetTargetProperty(tw, new PropertyPath(Border.WidthProperty));
                Storyboard storyBoard3 = new Storyboard();
                storyBoard3.Children.Add(tw);
                this.RegisterName("Width", this.ColorFulBorder);
                storyBoard3.Begin(this, true);
    
                storyBoard.Begin(this, true);
    
                
            }

    前台放个定义好的border,在文本框上绑定这俩个事件

  • 相关阅读:
    Android开发如何定制framework层服务
    Intellij IDEA通过SVN导入基于Springboot的maven项目以及对已有项目做更新
    intelliJ IDEA 怎么添加本地的idea web项目
    Android热修复之AndFix使用教程
    iOS友盟分享的使用总结
    iOS 传感器集锦
    IOS CALayer的属性和使用
    Swift使用Alamofire实现网络请求
    Android踩坑随笔Fragment中onActivityResult方法不被调用
    上周热点回顾(4.30-5.6)团队
  • 原文地址:https://www.cnblogs.com/AaronYang/p/2496557.html
Copyright © 2011-2022 走看看