在Silverlight 5中使用c#加载resourceDictionary [英] Loading resourceDictionary with c# in Silverlight 5

查看:82
本文介绍了在Silverlight 5中使用c#加载resourceDictionary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个基于Silverlight 5的项目。

我想用c#代码加载一个resourcceDictionary。

对于这项工作,我使用的是这个代码。



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 =>


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)



如何解决这个问题?

如果您有更好的方法加载resourceDictionary,请给我它。


How can I solve this problem ?
If you have better way to load resourceDictionary, please give me it.

推荐答案

请尝试以下代码并设置您的文件's属性(右键单击该文件)

1)构建动作:内容

2)复制到输出目录:如果更新则复制



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);





谢谢



Akash



Thanks

Akash


这篇关于在Silverlight 5中使用c#加载resourceDictionary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆