Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Silverlight 4.0 正在代码隐藏中更改/添加资源字典,请提供帮助_Silverlight 4.0_C# 4.0_Resourcedictionary - Fatal编程技术网

Silverlight 4.0 正在代码隐藏中更改/添加资源字典,请提供帮助

Silverlight 4.0 正在代码隐藏中更改/添加资源字典,请提供帮助,silverlight-4.0,c#-4.0,resourcedictionary,Silverlight 4.0,C# 4.0,Resourcedictionary,我目前正在开发一个silverlight应用程序,我仍然是这方面的初学者。 我想知道是否可以在代码隐藏(C#)中更改资源字典的源代码 在App.xaml中? 我尝试了下面的代码,但出现了一个异常,我从WCF服务获取样式文件夹名称,变量名为style(包含文件夹名称) 我在上有个错误 rDictionary.Source = new Uri(string.Format("Resources/{0}/Styles.xaml", "Default"), UriKind.RelativeOrAbsolu

我目前正在开发一个silverlight应用程序,我仍然是这方面的初学者。 我想知道是否可以在代码隐藏(C#)中更改资源字典的源代码 在App.xaml中? 我尝试了下面的代码,但出现了一个异常,我从WCF服务获取样式文件夹名称,变量名为style(包含文件夹名称)

我在上有个错误

rDictionary.Source = new Uri(string.Format("Resources/{0}/Styles.xaml", "Default"), UriKind.RelativeOrAbsolute);
上面写着

System.Exception: Error HRESULT E_FAIL has been returned from a call to a COM component.
   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)
   at System.Windows.ResourceDictionary.set_Source(Uri value)
   at FCStarFish.App..ctor()

我刚刚遇到了这个问题。在我的例子中,解决方案是将资源字典XAML文件的构建操作更改为“Content”,将Copy to Output Directory更改为“Copy if newer”,并将自定义工具更改为空字符串。默认值分别设置为Page/Do-copy/MSBuild:Compile。

我刚刚遇到这个问题。在我的例子中,解决方案是将资源字典XAML文件的构建操作更改为“Content”,将Copy to Output Directory更改为“Copy if newer”,并将自定义工具更改为空字符串。默认值分别设置为Page/Do copy/MSBuild:Compile。

首先按照下面Nattegreat提到的步骤进行操作,并在uritir前面加上“/”。它应该是这样的:

ResourceDictionary rDictionary = this.Resources.MergedDictionaries[0];
        rDictionary.Source = new Uri(string.Format("/Resources/Styles/{0}/Styles.xaml", style), UriKind.Relative);
        this.Resources.MergedDictionaries.Add(rDictionary);

首先,按照下面NateTheGreat提到的步骤,用“/”预先结束您的旅行。它应该是这样的:

ResourceDictionary rDictionary = this.Resources.MergedDictionaries[0];
        rDictionary.Source = new Uri(string.Format("/Resources/Styles/{0}/Styles.xaml", style), UriKind.Relative);
        this.Resources.MergedDictionaries.Add(rDictionary);
这有用吗

<Application.Resources>
    <ResourceDictionary x:Key="resourcestyles">
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary /> <!-- Dummy, this is the one we will replace -->
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
将MyApp替换为您的应用程序名称。

这有效吗

<Application.Resources>
    <ResourceDictionary x:Key="resourcestyles">
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary /> <!-- Dummy, this is the one we will replace -->
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
将MyApp替换为您的应用程序名称