C#实现ControlTemplate方法

藁城网站建设公司创新互联公司,藁城网站设计制作,有大型网站制作公司丰富经验。已为藁城近千家提供企业网站建设服务。企业网站搭建\外贸营销网站建设要多少钱,请找那个售后服务好的藁城做网站的公司定做!
现在主流的控件模板和样式是引用XAML资源,不过感觉没有C#代码实现那么灵活,介绍一下C#实现ControlTemplate方法:
- //控件呈现的显示内容1(这里为Image)
 - FrameworkElementFactoryfe=newFrameworkElementFactory(typeof(Image),"Image");
 - BitmapImagebi=newBitmapImage();
 - bi.BeginInit();
 - bi.UriSource=newUri(@"E:ChartControlHanYangChartControlImageMainBackground.jpg");
 - bi.EndInit();
 - fe.SetValue(Image.SourceProperty,bi);
 - //控件呈现的显示内容2(这里为TextBox)
 - FrameworkElementFactoryfe2=newFrameworkElementFactory(typeof(TextBox),"TextBox");
 - fe2.SetValue(TextBox.WidthProperty,100.0);
 - fe2.SetValue(TextBox.HeightProperty,100.0);
 - //把要呈现的显示内容封装起来
 - FrameworkElementFactoryf=newFrameworkElementFactory(typeof(Grid),"Grid");
 - f.AppendChild(fe);
 - f.AppendChild(fe2);
 - //控件模板
 - ControlTemplatect=newControlTemplate(typeof(Button));
 - ct.VisualTree=f;
 - //修改Button的Template
 - Buttonbtn=newButton();
 - btn.Template=ct;
 
以上介绍C#实现ControlTemplate方法。
Copyright © 2009-2022 www.wtcwzsj.com 青羊区广皓图文设计工作室(个体工商户) 版权所有 蜀ICP备19037934号