how to Add resource dictionaries by code in metro RRS feed

  • Question

  • Hi

    i need to add  themes\generic.xaml  to resource dictionary by code

    in silverlight i applied the following code and works fine


    ResourceDictionary dic1 = new ResourceDictionary();

    dic1.Source =

    new Uri("/SilverlightApplication1;component/Themes/generic.xaml", UriKind.Relative);

    now in metro how can i do that?, i tried the same code in silverlight but unfortunatly not successed, then i tried the following

    also not successed




    ResourceDictionary dic1 = new ResourceDictionary


    dic1.Source =


    new Uri("ms-resource:Themes/generic.xaml", UriKind.RelativeOrAbsolute);

    Any Help??

    Monday, November 14, 2011 7:50 AM

All replies

  • The Source URI needs to be absolute, not relative:

                ResourceDictionary dic1 = new ResourceDictionary();
                dic1.Source = new Uri(BaseUri, "themes/


    Monday, November 14, 2011 9:31 PM
  • thanks Rob

    i can get now the uri of generic file

    i need to set the theme of my custom button by code , i want to load the theme from generic.xaml by code which contains the following











    <Style TargetType



    <Setter Property






    <ControlTemplate TargetType="custom:CustomButton" x:Key



    <Grid x:Name



    <Rectangle x:Name="BodyElement" Width="200" Height



    Fill="Red" Stroke="Purple" RadiusX="16" RadiusY="16" />


    <TextBlock Text="Click Me" HorizontalAlignment



    VerticalAlignment="Center" />



















    i created the control by code and tried to load its theme but the following exception thrown when i set control template ('Error HRESULT E_FAIL has been returned from a call to a COM component.')

    the following is my code


    CustomButton b = new CustomButton



    ResourceDictionary dic1 = new ResourceDictionary


    dic1.Source =

    new Uri(BaseUri, "themes/generic.xaml"



    ResourceDictionary dic = new ResourceDictionary



    Resources = dic;

    b.Template = (


    ]; // exception thrown here

    Can you Help Me Please?



    Tuesday, November 15, 2011 6:31 AM