OK so I know that if I define a resource in XAML like this in a Window:

Code:
<Window.Resources>
     <SolidColorBrush x:Key="MyBrush" Color="Black" />
</Window.Resources>
then its easy for me to grab that resource from the code behind of that window, like this:
vb.net Code:
  1. DirectCast(FindResource("MyBrush"),SolidColorBrush)
or whatever, thats just off the top of my head so might not be 100% accurate but you get the idea.

Thats all well and good, but how can I access that resource from a class other than the code behind class for that window?
The situation is this - I am using a Converter (first time I have tried to use one) to set the background colour of a border in a listbox item based on the value of a property of the item that the listbox item is bound to... if that makes sense.
Here is my converter class:
vb.net Code:
  1. <ValueConversion(GetType(ProtoChat.UserStates), GetType(LinearGradientBrush))> _
  2. Public Class StatusToColourConverter : Implements IValueConverter
  3.  
  4.     Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
  5.         Dim BGBrush As New LinearGradientBrush
  6.         BGBrush.StartPoint = New Point(0.5, 0)
  7.         BGBrush.EndPoint = New Point(0.5, 1)
  8.         Dim Stops As New GradientStopCollection
  9.  
  10.         Select Case DirectCast(value, ProtoChat.UserStates)
  11.             Case ProtoChat.UserStates.Online
  12.                 Stops.Add(New GradientStop(Color.FromArgb(220, 226, 253, 234), 0.0))
  13.                 Stops.Add(New GradientStop(Color.FromArgb(220, 183, 240, 200), 0.21))
  14.                 Stops.Add(New GradientStop(Color.FromArgb(220, 110, 198, 135), 0.241))
  15.                 Stops.Add(New GradientStop(Color.FromArgb(220, 156, 228, 178), 0.991))
  16.             Case ProtoChat.UserStates.Away
  17.                 'Create gradient stops here
  18.             Case ProtoChat.UserStates.Busy
  19.                 'Create gradient stops here
  20.         End Select
  21.  
  22.         BGBrush.GradientStops = Stops
  23.         Return BGBrush
  24.     End Function
  25.  
  26.     Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
  27.         Return Nothing
  28.     End Function
  29. End Class

As you can see, it isnt exactly pretty and its not easy to work out the values for each gradient stop, so im hoping I can just define the brush as a resource in XAML (as its much easier to do in XAML, you just pass it a string of #CC6EC687 or whatever and it converts it to the correct brush) and then access that brush from my Converter. However I am open to other suggestions as there may be a better way of doing this! (would it be possible to use the same converter that XAML uses to convert the string into a colour but from code?)

Cheers
Chris