Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I am working on a project that based on Silverlight 5.
I want to load a resourcceDictionary by c# code.
For this work, I am using this code.
 
var url = new Uri(@"pack://application/PIPM2.MainVisual;component/"
                               + "Theme/Red.xaml", UriKind.Absolute);
            Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = url });
But I got this error =>
Error HRESULT E_FAIL has been returned from a call to a COM component.
Stack Trace =>
   at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
   at MS.Internal.XcpImports.SetValue(IManagedPeerBase obj, DependencyProperty property, String s)
   at MS.Internal.XcpImports.SetValue(IManagedPeerBase doh, DependencyProperty property, Object obj)
   at System.Windows.DependencyObject.SetObjectValueToCore(DependencyProperty dp, Object value)
   at System.Windows.DependencyObject.SetEffectiveValue(DependencyProperty property, EffectiveValueEntry& newEntry, Object newValue)
   at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
   at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isBindingInStyleSetter)
How can I solve this problem ?
If you have better way to load resourceDictionary, please give me it.
Posted 30-Nov-12 19:31pm
Edited 30-Nov-12 22:26pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Please try below code and Set your file's property (Right click on that file)
1) Build Action : Content
2) Copy to Output directory: Copy if newer
 
 ResourceDictionary rd = new ResourceDictionary();
 rd.Source = new Uri("/Theme/Red.xaml", UriKind.RelativeOrAbsolute);
 App.Current.Resources.MergedDictionaries.Clear();
 App.Current.Resources.MergedDictionaries.Add(rd);
 
Thanks
 
Akash
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 195
1 Afzaal Ahmad Zeeshan 152
2 ProgramFOX 130
3 Maciej Los 130
4 den2k88 80
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,657
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 1 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100