controltemplate:有关C#代码实现ControlTemplate

  现在主流Control控件模板和样式是引用XAML资源不过感觉没有c#代码实现那么灵活现介绍下代码实现 ControlTemplate思路方法:

以下是引用片段:
     //Control控件呈现显示内容1(这里为Image)
     FrameworkElementFactoryfe=FrameworkElementFactory(typeof(Image),"Image");
      BitmapImagebi=BitmapImage;
      bi.BeginInit;
      bi.UriSource=Uri(@"E:ChartControlHanYangChartControlImageMainBackground.jpg");
      bi.EndInit;
      fe.SetValue(Image.SourceProperty,bi);
      //Control控件呈现显示内容2(这里为TextBox)
      FrameworkElementFactoryfe2=FrameworkElementFactory(typeof(TextBox),"TextBox");
      fe2.SetValue(TextBox.WidthProperty,100.0);
      fe2.SetValue(TextBox.HeightProperty,100.0);
      //把要呈现显示内容封装起来
      FrameworkElementFactoryf=FrameworkElementFactory(typeof(Grid),"Grid");
      f.AppendChild(fe);
      f.AppendChild(fe2);
     //Control控件模板
     ControlTemplatect=ControlTemplate(typeof(Button));
     ct.VisualTree=f;
      //修改ButtonTemplate 
      Buttonbtn=Button;
      btn.Template=ct;


  
Tags:  c源代码 c语言代码 java源代码实现 controltemplate

延伸阅读

最新评论

发表评论