C#实现ControlTemplate方法

开发 后端
这里介绍C#实现ControlTemplate方法,现在主流的控件模板和样式是引用XAML资源,不过感觉没有C#代码实现那么灵活。

C#实现ControlTemplate方法

现在主流的控件模板和样式是引用XAML资源,不过感觉没有C#代码实现那么灵活,介绍一下C#实现ControlTemplate方法:

  1. //控件呈现的显示内容1(这里为Image)  
  2. FrameworkElementFactoryfe=newFrameworkElementFactory(typeof(Image),"Image");  
  3.  
  4. BitmapImagebi=newBitmapImage();  
  5. bi.BeginInit();  
  6. bi.UriSource=newUri(@"E:ChartControlHanYangChartControlImageMainBackground.jpg");  
  7. bi.EndInit();  
  8.  
  9. fe.SetValue(Image.SourceProperty,bi);  
  10.  
  11. //控件呈现的显示内容2(这里为TextBox)  
  12. FrameworkElementFactoryfe2=newFrameworkElementFactory(typeof(TextBox),"TextBox");  
  13. fe2.SetValue(TextBox.WidthProperty,100.0);  
  14. fe2.SetValue(TextBox.HeightProperty,100.0);  
  15.  
  16. //把要呈现的显示内容封装起来  
  17. FrameworkElementFactoryf=newFrameworkElementFactory(typeof(Grid),"Grid");  
  18. f.AppendChild(fe);  
  19. f.AppendChild(fe2);  
  20.  
  21. //控件模板  
  22. ControlTemplatect=newControlTemplate(typeof(Button));  
  23. ct.VisualTree=f;  
  24.  
  25. //修改Button的Template  
  26. Buttonbtn=newButton();  
  27. btn.Template=ct

以上介绍C#实现ControlTemplate方法。

【编辑推荐】

  1. 浅谈C#开发WinForm
  2. Visual C#使用COM组件
  3. C#做Screen Capture程序
  4. 在C#中声明API函数
  5. 描述C#开发WinForm
责任编辑:佚名 来源: 博客园
相关推荐

2010-01-22 13:45:36

C++代码

2009-08-19 17:00:07

C#实现PrintPa

2009-09-07 09:36:29

C# DisposeDispose方法

2009-09-11 11:39:23

C# RadioBut

2009-09-02 18:53:28

C#鼠标坐标

2009-04-20 10:09:46

C#优先队列.NET Framew

2009-08-25 14:26:28

C#播放AVI文件

2009-09-10 17:37:01

C# get post

2009-09-10 18:06:25

C# button快捷

2009-08-26 18:11:52

前台与后台方法互调

2009-09-11 09:59:47

2009-08-17 17:40:53

C# GetAllCu

2009-08-26 17:16:22

C# CheckSta

2009-08-26 09:50:08

C# GreetPeo

2009-12-23 17:42:37

WPF Control

2009-08-19 13:06:37

C#操作注册表

2009-03-27 10:10:13

c#远程启动远程管理

2009-08-17 16:59:47

C#转义字符双引号

2009-08-31 12:56:36

C#创建文件夹

2009-08-31 18:05:14

C#调用WalkTre
点赞
收藏

51CTO技术栈公众号