set home page
Added to the favorites
All articles(网络文学目录)
All Pictures(图片目录)
All Softwares(软件目录)
关于C#代码实现ControlTemplate_.net资料_编程技术
Writer:
aaa
Article type:
Programming skills(编程技巧)
Time:
2013/12/15 8:52:04
Browse times:
362
Comment times:
0
关于C#代码实现ControlTemplate_.net资料_编程技术
Head photo
Go homepage
Upload pictures
Write articles
关于C#代码实现ControlTemplate_.net资料_编程技术-你的首页-uuhomepage.com
现在主流的控件模板和样式是引用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;
There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)
Comments can't is empty(评论不能为空)
Disclaimer
Privacy Policy
About us
Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.