代码改变世界

Resource

2012-01-03 11:50  一一九九  阅读(501)  评论(0编辑  收藏  举报

Everything that inherits from frameworkElement has a Resources property. This creates a hierarchical set f resources for the application. Items declared in App.Resources are visible to the entrie application. Resource defined for a particular UserControl would be visible only to that control. if that UserControl has a Grid that defined resources, those items would be visible only to the children of the Grid, and so on. Additionally, resources in a more fine-graned scope can override items in a large scope. for example, some styles defined in a particular  UserControl would override styles declared at the application level.

Declaring resource is simple. All you have to do is add the XAML definition of the objecct you want to store to a ResourceDictionary(usually through the Resources property at the desired scope).

Colors cannot be applied to most WPF element properties like background or foreground. These properties require the use of Brush.

From <Sams.Teach.Yourself.WPF.in.24.Hours.Jun.2008>