关于C#代码实现ControlTemplate
2010-02-25 17:14
465 查看
现在主流的控件模板和样式是引用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;
本篇文章来源于 IT中国 转载请以链接形式注明出处 网址:http://www.it86.cc/dotnet/2008/0410/28124.shtml
//控件呈现的显示内容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;
本篇文章来源于 IT中国 转载请以链接形式注明出处 网址:http://www.it86.cc/dotnet/2008/0410/28124.shtml
相关文章推荐
- WPF关于C#代码实现Template
- 关于c#连接ftp进行上传下载实现原理及代码
- 以下是关于对称加密算法的C#实现代码,大家可以根据需要更改不同的算法,文中以Rijndael算法为例
- c# GridControl的模糊查询实现代码
- [WPF]使用C#代码实现DataTemplate
- 关于List Control控件实现翻页操作的基本代码
- WPF 关于C#代码实现ControlTemplate
- MSScriptControl详解(可实现在C#等语言中调用JAVASCRIPT代码)
- [C#]使用 C# 代码实现拓扑排序 dotNet Core WEB程序使用 Nginx反向代理 C#里面获得应用程序的当前路径 关于Nginx设置端口号,在Asp.net 获取不到的,解决办法 .Net程序员 初学Ubuntu ,配置Nignix 夜深了,写了个JQuery的省市区三级级联效果
- WPF 关于C#代码实现ControlTemplate
- 关于C# Math 处理奇进偶不进的实现代码
- c# 调用.bat文件的实现代码
- 关于MapXtreme for Java鹰眼实现思路及代码
- 关于vs2010下.net4.0 C#代码的混淆--网上各种破解版混淆工具的使用记录
- 关于《设计模式——基于C#的工程化实现》勘误的内容。感谢您对这本书的关心和支持
- C# 使用MSScriptControl.ScriptControl执行js代码,提示COM未注册的解法
- C# 中关于汉字与16进制转换的代码
- c#实现每隔一段时间执行代码(多线程)
- [转]C#实现人民币金额小写转大写的代码