阅读教程

Silverlight2.0入门教程(七): 使用控制模板自定义外观和触觉

[日期:2008-06-02] 来源:  作者:志伟
Silverlight2.0入门教程(七): 使用控制模板自定义外观和触觉,欢迎在线阅读Strutslight2.0教程.Using Control Templates to Customize a Control's Look and Feel

This is part seven of eight tutorials that walk through how to build a simple Digg client application using the Beta1 release of Silverlight 2.  These tutorials are intended to be read in-order, and help explain some of the core programming concepts of Silverlight.  Bookmark my Silverlight 2 Reference page for more of Silverlight posts and content. 

<Download Code> Click here to download a completed version of this Digg client sample. </Download Code>

How to Customize the Look and Feel of Controls

One of the most powerful features of the WPF and Silverlight programming model is the ability to completely customize the look and feel of the controls used within it.  This allows developers and designers to sculpt the UI of controls in both subtle and dramatic ways, and enables a tremendous amount of flexibility to create exactly the user experience desired.

In this tutorial segment we'll look at a few ways you can customize controls, and then close out by polishing up the user interface of our Digg application using these techniques.

Customizing the Content of Controls

In Part 1 of our tutorial we added a simple button control to the page and demonstrated how to set a custom "Push Me!" text string for its content.  We then wired up a "Click" event handler that executed code when it was clicked:

Silverlight2.0资料教程学习

This caused the button to render like below within the browser:

Silverlight2.0资料教程学习

One of the things that might surprise you about the Button control is that its "Content" property does not have to be a simple string like "Push Me!".  We can in fact set the "Content" property to be any sequence of Shapes or Controls we want. 

For example, we could embed a StackPanel with an <Image> and <TextBlock> control within it:

Silverlight2.0资料教程学习 

This will cause our Button to look like below at runtime.  Note that it still retains the same functionality behavior (push it and the button will still depress, and the click event handler will fire like before):

Silverlight2.0资料教程学习



[1] [2] [3] [4] [5] 下一页   
      
阅读:
录入:志伟

评论 】 【 推荐 】 【 打印
上一篇:Silverlight入门教程(六): 使用用户控制器Implement Master/Detail Scenarios
下一篇:Silverlight2.0入门教程(八): 使用WPF创建Digg桌面应用程序
本文评论       全部评论
发表评论


点评: 字数
姓名:

 
搜一下


 
本周热门教程
 

关于我们 | 广告合作 | 法律声明 | 联系站长 | 网站地图 | 网站搜索 | | Top ↑
Copyright © 志伟教程资料网 Powered by zhiweinet 1.0
 本栏目提供:Silverlight2.0入门教程(七): 使用控制模板自定义外观和触觉