You can also create and access resources by using code, or interchangeably between code and Extensible Application Markup Language (XAML). Note The resource files described in this topic are different than the resource files described in WPF Application Resource, Content, and Data Files and different than the embedded or linked resources described in Managing Application Resources (. The following example defines a Solid Color Brush as a resource on the root element of a page.The example then references the resource and uses it to set properties of several child elements, including an Ellipse, a Text Block, and a Button.When you define resources in markup, you assign the unique key through the x: Key Directive.Typically, the key is a string; however, you can also set it to other object types by using the appropriate markup extensions.The exception is when a theme element itself requests another resource.These references should be static resource references, for the reasons mentioned earlier.The deferral is necessary so that the runtime theme at the time the page loads applies properly to the application.However, static resource references to keys that are known to only exist in themes or as system resources are not recommended.
Dynamic resources work best for the following circumstances: Because the property being set must be a Dependency Property or Freezable property, most property changes can propagate to UI because a property change (the changed dynamic resource value) is acknowledged by the property system.Nonstring keys for resources are used by certain feature areas in WPF, notably for styles, component resources, and data styling.After you define a resource, you can reference the resource to be used for a property value by using a resource markup extension syntax that specifies the key name, for example: (it does not; its resource collection is empty), the lookup next checks the parent element of Button, which is Page.aspdotnet-suresh offers C#articles and tutorials,csharp dot net,articles and tutorials, VB.A resource is an object that can be reused in different places in your application. This overview describes how to use resources in XAML.