C#下给TextBlock动态添加下划线

2017-12-01 20:17:15来源:CSDN作者:mpegfour人点击

分享

C#中有时候为了增加交互效果需要给TextBlock动态增加下滑线,效果如图: 


实现代码如下: 

//下划线颜色            string colorString = "#FF00F077";            //线粗细            float thinck=2;            //生成TextDecorationCollection对象            TextDecorationCollection textDecorationCollection = new TextDecorationCollection();            TextDecoration textDecoration = new TextDecoration();            //String 转换Color            System.Windows.Media.Color color = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(colorString);//#FF00F077            textDecoration.Pen = new System.Windows.Media.Pen(new SolidColorBrush(color),thinck);            textDecorationCollection.Add(textDecoration);            //把textDecorationCollection给TextBlock 的TextDecorations            tab1.TextDecorations = textDecorationCollection;


最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台