新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
C#實(shí)現(xiàn)ControlTemplate方法
C#實(shí)現(xiàn)ControlTemplate方法

藁城網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司,藁城網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為藁城近千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)營(yíng)銷網(wǎng)站建設(shè)要多少錢(qián),請(qǐng)找那個(gè)售后服務(wù)好的藁城做網(wǎng)站的公司定做!
現(xiàn)在主流的控件模板和樣式是引用XAML資源,不過(guò)感覺(jué)沒(méi)有C#代碼實(shí)現(xiàn)那么靈活,介紹一下C#實(shí)現(xiàn)ControlTemplate方法:
- //控件呈現(xiàn)的顯示內(nèi)容1(這里為Image)
- FrameworkElementFactoryfe=newFrameworkElementFactory(typeof(Image),"Image");
- BitmapImagebi=newBitmapImage();
- bi.BeginInit();
- bi.UriSource=newUri(@"E:ChartControlHanYangChartControlImageMainBackground.jpg");
- bi.EndInit();
- fe.SetValue(Image.SourceProperty,bi);
- //控件呈現(xiàn)的顯示內(nèi)容2(這里為T(mén)extBox)
- FrameworkElementFactoryfe2=newFrameworkElementFactory(typeof(TextBox),"TextBox");
- fe2.SetValue(TextBox.WidthProperty,100.0);
- fe2.SetValue(TextBox.HeightProperty,100.0);
- //把要呈現(xiàn)的顯示內(nèi)容封裝起來(lái)
- 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#實(shí)現(xiàn)ControlTemplate方法。
名稱欄目:C#實(shí)現(xiàn)ControlTemplate方法
本文來(lái)源:http://www.dlmjj.cn/article/dpjhoso.html


咨詢
建站咨詢
