silverlight教程(4)---使用风格元素,以更好地概括外观与感觉

来源:百度文库 编辑:神马文学网 时间:2024/04/28 09:16:35
 wpf和silverlight支持一种风格机制,使我们能够控制拮据的财产价值作为一个可重复使用的资源,我们可以存储这些风格报关单单独文件从网页,并重新使用它们横跨多个控制和网页应用程序(以及再利用他们跨多个应用程序) ,这是在概念上类似于使用CSS与HTML的时候,做基础定制的情况。

Note: In addition to defining basic property settings (Color, Font, Size, Margins, etc), styles in WPF and Silverlight can also be used to define and re-use Control Templates - which enable super rich skinning and adaptation of control structure (and support customization scenarios not possible with CSS in HTML today).  I discuss Control Templates in Part 7 of this series. 注:除界定基本属性的设置(颜色,字体,大小,利润率等) ,风格wpf和silverlight也可以被用来界定和再利用控制模板-使超级富豪的s kinning功能和适应的控制结构(并支持个性化的情况,不可能同的CSS在HTML今日) ,讨论控制模板,在第7部的这一系列。

For our Digg sample application we'll define our Style declarations within the App.xaml file of our project.  This will enable them to be reused across all pages and controls in the application:我们digg采样应用,我们将确定我们的作风报关单内app.xaml档案,我们的项目,这将使他们能够重复使用,所有的页面和控制中的应用:

Let's start by encapsulating styles for the control (and the title contained within it) of our Digg page:让我们先灌封作风,为控制(以及标题中包含它)我国Digg页面:

We can create two Style elements within our App.xaml file that encapsulate the and settings we were previously declaring inline using the markup below:我们可以制造两个风格分子,我们app.xaml文件,概括了设置我们以前曾经申报直列用标记如下:

Note how we are giving each Style a unique "Key" value above.  We can then update our and controls to reference the Styles using these keys.  We'll be using a XAML feature called "markup extensions" to do this.  Markup extensions are used when there are non-literal values that we want to set (another example of where we'll use this feature is with databinding expressions).说明我们如何让每一个风格独特的"钥匙"的价值以上,我们便可以更新我们的管制,以提述方式使用这些钥匙,我们都会用xaml功能叫做"标记延伸"做到这一点。标记延用的时候,是有非字面的价值观,我们要设置(另一个例子,我们将在使用此功能是和数据绑定表达式) 。

When we update the other controls within our Page.xaml file to use styles as well, we are left with a file that looks like below:当我们更新其他管制措施,我们page.xaml档案使用作风好,我们只剩下一个文件看起来像下面:

Encapsulate the style settings this way allows developers to better focus on the behavior semantics of the application, and also enables us to re-use styles across other controls/pages we build.概括了样式设置这种方式允许开发,以更好地着眼于行为语义学的应用,也使我们得以重新使用风格跨越其他管制/页,我们建立的。

Note: One issue to be aware of with Beta1 is that the error message when you mistype style names and property declarations is not very clear (it raises an exception but doesn't tell you what isn't set correctly).  This will be improved in Beta2. 注:一个问题,他们必须明白,与素beta1是错误的讯息,当你错误的作风姓名及财产申报不很清楚(它提出了一个例外,但并没有告诉你什么是不正确设置) ,这将得到改善在间谍软件。 In the meantime if you see an error loading a style make sure to look carefully for typos. 在此期间,如果你看到一个错误装载的风格一定要仔细看看,为错别字。