PassCodeIt is very easy to access the resources we define in Silverlight. First, we define the following resource:
Code
1 < Usercontrol X: Class = "Eightball. Page"
2 Xmlns = "Http://schemas.microsoft.com/client/2007"
3 Xmlns: x = "Http://schemas.microsoft.com/winfx/2006/xaml"
4 Width = "400" Height = "300" >
5 < Usercontrol. Resources >
6 < Lineargradientbrush X: Key = "Backgroundbrush" >
7 < Lineargradientbrush. gradientstops >
8 < Gradientstop Offset = "0.00" Color = "Yellow" />
9 < Gradientstop Offset = "0.50" Color = "White" />
10 < Gradientstop Offset = "1.00" Color = "Purple" />
11 </ Lineargradientbrush. gradientstops >
12 </ Lineargradientbrush >
13 </ Usercontrol. Resources >
14
15 </ Usercontrol >
In the resources attribute of usercontrol, we define a lineargradientbrush type resource and define its index as "backgroundbrush". Then we can access this resource through the following code.
Code
Code
Lineargradientbrush brush = (Lineargradientbrush) This . Resources [ " Backgroundbrush " ];
Color color = Brush. gradientstops [ 0 ]. Color;
Brush. gradientstops [ 0 ]. Color = Brush. gradientstops [ 2 ]. Color;
Brush. gradientstops [ 2 ]. Color = Color;
Note that Silverlight only supports static resources, so you cannot replace the defined resources with other objects, as shown in the following code:
Code
code highlighting produced by actipro codehighlighter (freeware)
http://www.CodeHighlighter.com/
--> Code
solidcolorbrush brush = New solidcolorbrush (colors. yellow);
This . resources [ " backgroundbrush " ] = brush;