1

我正在开发一个基于 Silverlight 5 的项目。我想通过 c# 代码加载资源字典。对于这项工作,我正在使用此代码。

var url = new Uri(@"pack://application/PIPM2.MainVisual;component/" + "Theme/Red.xaml", UriKind.Absolute); Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = url });

但是我得到了这个错误=>

错误消息 => 错误 HRESULT E_FAIL 已从对 COM 组件的调用中返回。

堆栈跟踪 => 在 MS.Internal.XcpImports.CheckHResult(UInt32 hr) 在 MS.Internal.XcpImports.SetValue(IManagedPeerBase obj, DependencyProperty 属性, String s) 在 MS.Internal.XcpImports.SetValue(IManagedPeerBase doh, DependencyProperty 属性, 对象obj)在 System.Windows.DependencyObject.SetObjectValueToCore(DependencyProperty dp,对象值)在 System.Windows.DependencyObject.SetEffectiveValue(DependencyProperty 属性,EffectiveValueEntry&newEntry,Object newValue)在 System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty 属性,EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry,ValueOperation 操作)在 System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp,对象值,布尔 allowReadOnlySet,布尔 isBindingInStyleSetter)

我怎么解决这个问题 ?如果你有更好的加载资源字典的方法,请给我。

4

0 回答 0