【发布时间】:2013-09-08 01:54:33
【问题描述】:
我在我的 xaml 中定义了一个资源:
<core:WidgetBase xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" x:Class="....Silverlight.LiquidityConstraintsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:core="clr-namespace:...Silverlight;assembly=....Silverlight"
xmlns:local="clr-namespace:....Silverlight"
mc:Ignorable="d">
<core:WidgetBase.Resources>
<SolidColorBrush x:Key="..." />
</core:WidgetBase.Resources>
...
我正在尝试从代码中设置它:
void _administrationClient_GetByFilterModuleSettingCompleted(object sender, GetByFilterModuleSettingCompletedEventArgs e)
{
this.Resources["..."] = new SolidColorBrush(Colors.Red);
}
但我得到了错误:
方法或操作没有实现。
堆栈跟踪:
at System.Windows.ResourceDictionary.set_Item(Object key, Object value)
at ....Silverlight.LiquidityConstraintsView._administrationClient_GetByFilterModuleSettingCompleted(Object sender, GetByFilterModuleSettingCompletedEventArgs e)
at ....Service.AdministrationServiceClient.OnGetByFilterModuleSettingCompleted(Object state)
当我向服务器发送请求以获取颜色时,会发生这种情况,然后当它返回时,我尝试将该颜色设置为资源,即使我尝试将其设置为红色,它也会失败。
如果有帮助,我设置它的方法是从 WCF 调用到服务器的异步回调方法。
【问题讨论】:
-
它应该可以工作。我在最后尝试过它可以工作。你到底在哪里设置这个值你能分享更多的代码吗?
-
我同意,该错误与此典型操作不匹配。我们可以有一个堆栈跟踪吗?
-
也许这是因为:
Silverlight does not support dynamic resources. All resource references to keyed resources in XAML are static.Link on MSDN。
标签: wpf silverlight colors resources