博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WPF 后台重写 DataTemplate
阅读量:5268 次
发布时间:2019-06-14

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

///     /// 配置类    ///     public static class GridControlDeploy    {        ///         /// 重写 DataTemplate 表头        ///         /// GridControl 实际宽度        /// 表头名称列表        /// 
public static DataTemplate DynamicAddColumn(double Widths, List
StrList) { //去掉两头宽度 Widths = Widths - 35; var gd = new FrameworkElementFactory(typeof(StackPanel)); gd.SetValue(StackPanel.BackgroundProperty, new SolidColorBrush((Color)ColorConverter.ConvertFromString("#D1E8FF"))); gd.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal); gd.SetValue(StackPanel.HeightProperty, 30.0); var Bor1 = new FrameworkElementFactory(typeof(Border)); Bor1.SetValue(Border.WidthProperty, 16.0); Bor1.SetValue(Border.BackgroundProperty, new SolidColorBrush((Color)Colors.White)); Bor1.SetValue(Border.BorderThicknessProperty, new Thickness(0, 0, 1, 1)); Bor1.SetValue(Border.BorderBrushProperty, new SolidColorBrush((Color)ColorConverter.ConvertFromString("#D6D6D6"))); gd.AppendChild(Bor1); foreach (var item in StrList) { var Bor3 = new FrameworkElementFactory(typeof(Border)); Bor3.SetValue(Border.BorderThicknessProperty, new Thickness(0, 0, 1, 1)); Bor3.SetValue(Border.BorderBrushProperty, new SolidColorBrush((Color)ColorConverter.ConvertFromString("#D6D6D6"))); Bor3.SetValue(Border.WidthProperty, Widths / StrList.Count()); var textblockFEF = new FrameworkElementFactory(typeof(TextBlock)); textblockFEF.SetValue(TextBlock.TextProperty, item); textblockFEF.SetValue(TextBlock.ToolTipProperty, item); textblockFEF.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center); textblockFEF.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center); textblockFEF.SetValue(TextBlock.TextWrappingProperty, TextWrapping.Wrap); Bor3.AppendChild(textblockFEF); gd.AppendChild(Bor3); } var Bor2 = new FrameworkElementFactory(typeof(Border)); Bor2.SetValue(Border.WidthProperty, 19.0); Bor2.SetValue(Border.BackgroundProperty, new SolidColorBrush((Color)Colors.White)); Bor2.SetValue(Border.BorderThicknessProperty, new Thickness(0, 0, 1, 1)); Bor2.SetValue(Border.BorderBrushProperty, new SolidColorBrush((Color)ColorConverter.ConvertFromString("#D6D6D6"))); gd.AppendChild(Bor2); var dataTemplate = new DataTemplate { VisualTree = gd }; return dataTemplate; } }

 重写表头

 

转载于:https://www.cnblogs.com/SeNaiTes/p/10383869.html

你可能感兴趣的文章
SWIFT国际资金清算系统
查看>>
Sping注解:注解和含义
查看>>
站立会议第四天
查看>>
如何快速掌握一门技术
查看>>
利用AMPScript获取Uber用户数据的访问权限
查看>>
vagrant 同时设置多个同步目录
查看>>
python接口自动化28-requests-html爬虫框架
查看>>
生成随机数的模板
查看>>
Mysql 数据库操作
查看>>
转:linux终端常用快捷键
查看>>
A-Softmax的总结及与L-Softmax的对比——SphereFace
查看>>
UVa 11059 最大乘积
查看>>
数组分割问题求两个子数组的和差值的小
查看>>
composer 报 zlib_decode(): data error
查看>>
linux下WPS的使用
查看>>
Web Api 利用 cors 实现跨域
查看>>
hdu 3938 并查集
查看>>
instanceof
查看>>
《深入分析Java Web技术内幕》读书笔记之JVM内存管理
查看>>
python之GIL release (I/O open(file) socket time.sleep)
查看>>