You guys will come back this time around.
We're going to be looking at shared resources.
So shared resources would be an extension of what we kind of looked at earlier with the extension,
except it's not going to be so tightly coupled to any one control.
Right.
So let's just start off by adding a new class, right click, add new class, and then I'm going to
call it Shared Resources, Click Add.
And then we're making this one static class.
So this is a static class called Shared Resources.
And then in here we can define some public static read only properties, right?
So let us start off by saying maybe that we want a certain color, right, for our font.
So static public static grid only and I'm going to call it what the type is going to be color.
So color is a type and let's call it font color.
I spelled color with a U, so you're always going to see that and then we're going to give it a value,
right?
So our font color here is going to be color dot and we can do from in from RGV, etc. Let's do a RGV
thing that's easy enough to get by with.
So if we wanted it to be all our GBS, red, green and blue, we can use integers between zero and 255.
If you're familiar with CCIS, that shouldn't be a foreign concept to you.
So we can use something like zero comma, zero comma and 25 for argument's sake.
So that would give us a more blue font color.
All right.
We can also set other values.
So I could set like background color.
I could set for call, I could set all sorts of things.
I mean, once I have the data type and I give it a name and then can give it to value, it can be put
in that static shared resources file not to use this resource or any of the resources from this file.
I just need to go to a control.
Let me go to the new page one and then up here I want to do something similar where I have to include
the namespace example and s colon and then I'm going to give it a name, let's call it resources and
I'm going to say you are equal to similar hyphen namespace add colon and the namespace for my shared
resource file is indeed still my first Maui up.
Well, it's of course it goes in a folder.
We're not paying attention and the folder structure is too tough here because I could have easily put
this in the resources folder, so let me actually do that.
So I'm going to move that shared resources file to the resources folder.
And then what I'm going to do is synchronize to the namespace so that we can make sure it's in the namespace.
So at this point, when I'm including it in the XAML, I have to make sure that I am pointing it to
the correct namespace.
So we're a new page one class namespace namespace R is my first way up.
That's resources, right?
So now we know where this button is now to make reference to it in the code, wherever I want that color
to be used.
Let's see, I want it in the label here.
Then I would go for the attribute that this text colour is equal to and then open my curly brace.
First of all, I would say x colon static.
So that's it knows that.
Okay, I'm getting my value from a static member.
So static remember let me get my spelling right and that's equal to and then we say resources.
That's our alias for our namespace of top resources.
Share is shared resources, which is the name of our file and then font color.
So here we're seeing go and fetch the phone call from from this static shared resource file.
So anywhere in our code that we want to share that color, we can do something that and we can have
once again as many resources listed out in here that we know we want to remain consistent across the
entire app.
So you can go ahead and test that old.
You can go ahead and run it, put it in multiple places, and just go ahead and ensure that whatever
color you would have defined here is actually being displayed in those areas.