We have spoken briefly about resources before. Let us take a closer look on how they work. We click on the resources tab. This is the place for all the resources that are within the scope of my current selection.
Right now, since I do not have any thing selected, the only resources that I have accessible are those found in the application or on the Window itself. If I select something on the art board say, the rectangle, now its scope is also displayed so I can see the resources to find if that is the parents.
I will switch back to the properties inspector and I am going to change my rectangle to use a linear gradient. I have used the mouse wheel to scroll up through the properties and selecting the fill property and changing it to linear gradient. I am going to create a red color for one of my gradient stuffs but I am going to define as a resource.
When I click the button to convert it to resource, the color resource dialog is brought up. Every resource must have a name. In this case, I am just going to call it red. Resources names do not necessarily have to be unique but they have to be unique at each scope. This means that if I have a red to find my documents, I cannot find another resource named to red on the same document.
I could however, have that resource to find it in application and then if I was using the resource, the element would look to its parents and continuing up the tree until it found the element it was looking for. I am going to define this resource on these documents, the Window. I could not click this button to find the resource in my application or I could click this button to create a new resource dictionary.
A resource dictionary is a separate file where I can keep my resources together and distribute them to my teammates. For now, I am just going to create the resource and hit okay.
The brush inspector is now still showing me that I am working with a linear brush here but it is showing them a color is now set to color resource or my red. The marker has also changed to green as green indicates a resource is currently in used. I can now select one of my rectangles including what rectangle with a solid fill, switch to the color resources tab and select that red.
In this case, even though the red was used in the linear gradient in one rectangle, I can used that color to set the entire fill. I am going to go back to the large rectangle and this time I am going to convert the entire brush to resource. I am going to need black to red as that describes how the gradient looks and press okay.
Now, the entire brush at the door has been replaced and that it is showing down using a local brush resource, black to red in this case. If I choose one of my other rectangles and I will switch to the brush resource tab, I can click black to red in the entire gradient is displayed.
I am going to use a selection tool to move the out from behind image so you can see it a little more. Now, since the gradient uses a red that we have established as a resource, I can modify that and it gets updated in all the places that it is used.
I switch to my resource tab and on my Window, we see both the red and the black to red. The red is a color resource and when I click on the chevron, I can modify that color. The smaller rectangle here changes to a new color immediately and the gradient stuff in my two brushes changes as well since they are linked to my resource.
Now, those property markers that we looked at earlier, I am going to switch to my properties and I am going to use the property marker to convert this to a local value. When I do this the connection to the resource is severed. So, now when I go to the resource tab and change that red again, you will notice that the rectangle that I severed the connection does not change even as I modify the color.
You can define a resource from practically any property type. In this case, we have used colors and we have used brushes but you can also use control templates. You can use doubles or enumerations setting them all as resources and using them throughout your documents.
Resources can also be assigned directly from the resource pallet. Let us say I wished to assign this black to red to that rectangle that is solid. I can click on the resource and drag it directly to the rectangle and when I released it will ask me which property I want to apply to.
In this case, if I say applied to the fill, the rectangle accepts the black to red resource. If I switch back to the properties tab, you will see that the fill for that object now has the green property marker to indicate that is used in the resource that I just assigned to it.
We have completed our tour now of the expression blend application but we have really only scratch the surface of what blend is capable of. As we continue with the lessons, we will work more in depth more into these features to unlock the capabilities of blend.
Transcription by:
Scribe4you Transcription Services