现在主流的控件模板和样式是引用XAML资源,不过感觉没有C#代码实现那么灵活,现介绍一下代码实现 ControlTemplate的方法:
以下是引用片段: //控件呈现的显示内容1(这里为Image) FrameworkElementFactory fe = new FrameworkElementFactory(typeof(Image), "Image"); BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.UriSource = new Uri(@"E:ChartControlHanYangChartControlImageMainBackground.jpg"); bi.EndInit(); fe.SetValue(Image.SourceProperty, bi); //控件呈现的显示内容2(这里为TextBox) FrameworkElementFactory fe2 = new FrameworkElementFactory(typeof(TextBox), "TextBox"); fe2.SetValue(TextBox.WidthProperty,100.0); fe2.SetValue(TextBox.HeightProperty, 100.0); //把要呈现的显示内容封装起来 FrameworkElementFactory f = new FrameworkElementFactory(typeof(Grid), "Grid"); f.AppendChild(fe); f.AppendChild(fe2); //控件模板 ControlTemplate ct = new ControlTemplate(typeof(Button)); ct.VisualTree = f; //修改Button 的Template Button btn = new Button(); btn.Template = ct; | 下一篇:教你如何在C语言使用位运算实现循环移位 循环移位区别于一般移位的是移位时没有数位的丢失。循环左移时,用从左边移出的位填充字的右端,而循环右移时,用从右边移出的位填充字的左侧。这种情况在系统程序中时有使用,在一些控制程序中用得也不少。
设有数据说明:
a=01111011,循环左移2位 正确结果: 11101101
过程:
b=a>>(8-2) 用来得到正常左移丢失的位和循环移位后其正确位置 b=00000001;
a=a<<2;左移 a=11101100
a=a|b; a=11101101
如果不是用中间变量 a=(a>&...[查看详情] |