0 votes
in C Sharp by

What are Resources in WPF?

1 Answer

0 votes
by
Windows Presentation Foundation (WPF) resources provide a simple way to reuse commonly defined objects and values. Resources in WPF allow you to set the properties of multiple controls at a time. For example, you can set the background property on several elements in a WPF application using a single resource.
 
The best way of defining the resources is on a Window or Page element level. Any resource that you define for an element also applies to their child elements of that element. For example, if you define a resource for a Window element that has a Grid as a child element, then the resources defined for the window elements can also be used by the grid element. However, if you define a resource for the grid element, then the resource applies only to the child elements of the grid element.
 
Syntax for resources in WPF,
 
<elementName propertyName="{markupExtension keyName}">

   <!-Content -->

</elementName>
 
Where,
  • elementName: Name of the element that uses the resource.
  • propertyName: Name of the property that takes its value from the resource.
  • markupExtension: Define type of resource.
  • keyName: key name of the resource, which is unique string to identify the resource.

There are two types of resource, namely,

  • Static Resource
  • Dynamic Resource

Related questions

0 votes
0 votes
0 votes
asked Mar 17, 2020 in C Sharp by Hodge
0 votes
asked Mar 17, 2020 in C Sharp by Hodge
0 votes
asked Mar 17, 2020 in C Sharp by Hodge
0 votes
0 votes
asked Mar 17, 2020 in C Sharp by Hodge
0 votes
0 votes
asked May 28, 2022 in WPF by sharadyadav1986
...