Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > .NET > C#.NET > WPF 关于C#代码实现ControlTemplate
【标  题】:WPF 关于C#代码实现ControlTemplate
【关键字】:WPF,C#,ControlTemplate
【来  源】:http://blog.csdn.net/artlife/archive/2007/01/16/1484363.aspx

WPF 关于C#代码实现ControlTemplate

Your Ad Here

现在主流的控件模板和样式是引用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;
CLR内核随记(1):【上一篇】
解决右键弹出菜单慢的问题:【下一篇】
【相关文章】
  • C#实现类似qq的屏幕截图程序
  • 闲话WPF之二三(WPF中的ControlTemplate)
  • 我讨论WPF/E,Orcas,IIS7和MIX的采访录像
  • C#常用字符串函數
  • C#写“监视器”
  • C#经典书籍
  • C#实现木马程序!
  • 闲话WPF之二二(WPF中的Style)
  • WPF/E - 使用 Transforms 和 Opacity Masks 创建 Reflection 反射效果
  • 用WPF和.NET开发的下一代Yahoo Messenger
  • 【随机文章】
  • exchange forwarder
  • weblogic的几个基础问题
  • 入侵检测技术剖析(2)
  • css缩写的主要规则
  • JSP实用篇
  • NC服务器的一天
  • 男子见姘妇与人唠嗑吃醋 找人刺死“情敌”
  • IPC经典入侵,比3389实用
  • FreeBSD的安装
  • JDBC-ODBC翻页例子
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.