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方法
当前URL:http://www.hantingmc.com/qtweb/news2/181602.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联