Bug accessing application resources in SL2B1 app
Last post 05-11-2008 5:29 AM by y_makram. 1 replies.
Sort Posts:
05-11-2008 2:10 AM
Bug accessing application resources in SL2B1 app

 Hi everyone,

 I have a few application resources in my Silverlight 2 Beta 1 app:

    <Application.Resources>
        <FontFamily x:Key="FontNormal">Trebuchet MS</FontFamily>
        <System:Double x:Key="TextSizeNormal">12</System:Double>
        <FontFamily x:Key="FontTitle1">Trebuchet MS</FontFamily>
        <System:Double x:Key="TextSizeTitle1">14</System:Double>
        <Color x:Key="ColorForegroundTitle1">#FF4186B2</Color>
        <Color x:Key="ColorClickableText">#FF0000C9</Color>
    </Application.Resources>

and I have to access these resources in the code. The line

      Double TextSizeNormal = Convert.ToDouble( App.Current.Resources["TextSizeNormal"] );

works perfectly fine. But the line

      Object c = App.Current.Resources["ColorClickableText"];

doesn't work. Actually, App.Current.Resources["ColorClickableText"] returns null.

Bug?

Best regards,

Laurent
 

LaurentD

Joined on 05-05-2008
Posts 2
05-11-2008 5:29 AM
Marked as Answer
Re: Bug accessing application resources in SL2B1 app

The color object does not support direct content, nor it is designed to be instantiated directly from XAML, consider using SolidColorBrush instead, example:

 <SolidColorBrush x:Key="ColorClickableText" Color="#FF0000C9" />

Then from your code:

Object c = App.Current.Resources["ColorClickableText"];

If you only need the color object you can get it from the Color property of the brush 

Thanks
Yasser Makram
My Blog: http://www.silverlightrecipes.com
Sr. Architect
Santeon Inc. Microsoft Silverlight Partner, Solution Provider

y_makram

Joined on 06-07-2007
Cairo, Egypt
Posts 1,123