博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
潜移默化学会WPF--Border,焦点移动
阅读量:6276 次
发布时间:2019-06-22

本文共 3731 字,大约阅读时间需要 12 分钟。

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,在文本框上绑定这俩个事件

转载地址:http://aygpa.baihongyu.com/

你可能感兴趣的文章
话说模式匹配(5) for表达式中的模式匹配
查看>>
《锋利的SQL(第2版)》——1.7 常用函数
查看>>
《Arduino家居安全系统构建实战》——1.5 介绍用于机器学习的F
查看>>
jquery中hover()的用法。简单粗暴
查看>>
线程管理(六)等待线程的终结
查看>>
《HTML5 2D游戏编程核心技术》——第3章,第3.7节反转滚动方向
查看>>
spring boot集成mongodb最简单版
查看>>
DELL EqualLogic PS存储数据恢复全过程整理
查看>>
《Node.js入门经典》一2.3 安装模块
查看>>
《Java 开发从入门到精通》—— 2.5 技术解惑
查看>>
又是神经网络!还能用来盗取XX女演员信息
查看>>
Ruby 1.9概要(5) 异常
查看>>
《网站性能监测与优化》一2.2 交易网站
查看>>
Ceph分布式存储学习指南1.5 Ceph块存储
查看>>
《Tableau 8权威指南》—— 1.1 Tableau是什么
查看>>
Python语言的创始人解释为什么Python数组的索引从0开始
查看>>
《Netty官方指南》把Netty当做一个通用的库
查看>>
sicp 2.3小结习题尝试解答
查看>>
Linux 性能诊断 perf使用指南
查看>>
实操分享:看看小白我如何第一次搭建阿里云windows服务器(Tomcat+Mysql)
查看>>