RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
C#实现ControlTemplate方法

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方法。


当前文章:C#实现ControlTemplate方法
网页链接:http://www.jxjierui.cn/article/dpjhoso.html