控件模板Template(Silverlight)

阅读: 53 评论: 0 作者: hahacjh 发表于 2010-02-28 12:17 原文链接

1.在控件声明中直接定义;

 

  
    
< Button Content = " Button1 " >
< Button.Template >
< ControlTemplate TargetType = “Button” >
<!-- 在此ControlTemplate‐‐ >
</ ControlTemplate >
</ Button.Template >
</ Button >


2.在容器的资源属性中定义:

 

代码
   
     
< StackPanel >
< StackPanel.Resources >
< Style x:Key = " ButtonStyle " TargetType = " Button " >
< Setter Property = " Template " >
< Setter.Value >
< ControlTemplate TargetType = " Button " >
<! ‐‐在此定义ControlTemplate ‐‐ >
</ ControlTemplate >
</ Setter.Value >
</ Setter >
</ Style >
</ StackPanel.Resources >
< Button Style = " {StaticResource ButtonStyle} " Content = " Button1 " />
</ StackPanel >

 

 

 

3.app.xaml文件中定义:

代码
   
     
< Application.Resources >
< Style TargetType = " TextBlock " x:Key = " TextBlockPrompt " >
< Setter Property = " VerticalAlignment " Value = " Bottom " />
< Setter Property = " HorizontalAlignment " Value = " Left " />
< Setter Property = " FontFamily " Value = " Verdana " />
< Setter Property = " FontSize " Value = " 14 " />
< Setter Property = " FontWeight " Value = " Medium " />
< Setter Property = " Foreground " Value = " Blue " />
</ Style >
</ Application.Resources >

 

前段绑定方法:

  
    
< Button Style = " {StaticResource TextBlockPrompt} " Content = " Button1 " />

 

评论: 0 查看评论 发表评论

找优秀程序员,就在博客园


最新新闻:
· IBM发布第五代X架构 打破X86系统30年技术局限(2010-03-03 22:47)
· 互联网手机业务成香馍馍 上海电信盯牢3G市场(2010-03-03 22:38)
· Twitter信息总量即将突破100亿条大关(2010-03-03 22:34)
· Opera为何无法进一步拓展市场(2010-03-03 21:38)
· Symbian版 Skype登陆诺基亚Ovi Store(2010-03-03 21:04)

编辑推荐:Opera为何无法进一步拓展市场

网站导航:博客园首页  个人主页  新闻  闪存  小组  博问  社区  知识库

你可能感兴趣的:(silverlight)