Resources are generally definition related with some object that you just expect to use more often than once. It is the skill to store data locally for controls or for the current window or globally for the whole applications.
Defining an entity as a resource allows us to access it from another position what it means is that the object can be reuse. Resources are define in resource dictionaries and any object can be defined as a resource effectively creation it a shareable asset. A single key is specified to an XAML resource and with that key, it can be referenced by using a Static Resource mark-up extension.
Resources can be of two types −
A Static Resource is a once lookup, whereas a Dynamic Resource works more like a data binding. It remembers that a property is related with a exacting resource key. If the object connected with those key changes, dynamic resource will update the target property.
Here's a simple application for the SolidColorBrush resource.
When you click the "Change Resource" button, you will see that the rectangle with Dynamic Resource will modify its colour to Red.
Resources are defined in resource dictionaries, but there are many places where a resource dictionary can be define. In the above instance, a resource dictionary is defined on Window/page level. In what dictionary a resource is define instantly limits the scope of that resource. So the scope, i.e. where you can use the resource, depends on where you've defined it.
As far as the scope of the resource is afraid, the most often are application level, page level, and a particular constituent level like a Grid, Stack Panel, etc.
The above application has resources in its Window/page level.
Resource dictionaries in XAML apps imply that the resource dictionaries are kept in divide files. It is followed in almost all XAML apps. Essential resources in divide files can have the following reward −
So, how do we describe our resources in a resource dictionary in a separate file? Well, it is very easy, just add a new resource dictionary through ocular Studio by following steps given below −
Let’s now take the same instance, but here, we will define the resource dictionary in app level. The XAML code for MainWindow.xaml is as follows –
Here is the performance in DictionaryWithBrush.xaml –
Here is the implementation in app.xaml –
When the beyond code is compiled and executed, it will create the following output −
When you click the Change Resource button, the rectangle will change its colour to Red.
We recommend that you execute the above code and try a few more resources (for instance, background colour).
Windows Presentation Foundation(WPF) Related Interview Questions
|C#. NET Interview Questions||ASP.NET Interview Questions|
|Advanced Dot Net Interview Questions||OOPS Interview Questions|
|MVC Framework Interview Questions||MVVM Interview Questions|
|Windows Communication Foundation (WCF) Interview Questions||Dot Net Framework Interview Questions|
|Advanced C# Interview Questions||XAML Interview Questions|
|Win32 Api Interview Questions||Basic C Interview Questions|
|Asp Dot Net Mvc 4 Interview Questions||Windows Workflow Foundation Interview Questions|
Windows Presentation Foundation(WPF) Related Practice Tests
|C#. NET Practice Tests||ASP.NET Practice Tests|
|OOPS Practice Tests||Windows Communication Foundation (WCF) Practice Tests|
|Dot Net Framework Practice Tests|
Windows Presentation Foundation(wpf) Tutorial
Windows Presentation Foundation(wpf)
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.