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.