[英]Using a Markup Extension as value of property Setter in XAML. {0} is not valid for Setter.Value. The only supported MarkupExtension types are
Below is a very small example how to get this exception
. 下面是一个非常小的示例,说明如何获取此
exception
。 This is already a known issue (for more than 7 years!). 这已经是一个已知问题(超过7年!)。 Is there already a solution for that?
已经有解决方案了吗?
FooExtension is not valid for Setter.Value.
FooExtension对于Setter.Value无效。 The only supported MarkupExtension types are
唯一受支持的MarkupExtension类型是
DynamicResourceExtension and BindingBase or derived types.DynamicResourceExtension和BindingBase或派生类型。
public class FooExtension : MarkupExtension
{
public string Key { get; set; }
public override object ProvideValue(IServiceProvider serviceProvider)
{
return new SolidColorBrush((Color)ColorConverter.ConvertFromString(Key));
}
}
This is not the original class/MarkupExtension I'm using, but the logic (return SolidColorBrush
) are identical and it gives exactly the same error/behavior. 这不是我正在使用的原始类/ MarkupExtension,但是逻辑(返回
SolidColorBrush
)是相同的,并且给出了完全相同的错误/行为。
Background="{extensions:Foo Key=#FFF37C21}"
The extension
worked until yesterday for more than 1 year! 该
extension
一直工作到昨天超过1年! Including every Windows, VisualStudio or any other update! 包括每个Windows,VisualStudio或任何其他更新! And now since 1 day I got this bug behavior during the design time!
现在从1天开始,我在设计期间就收到了这个错误行为!
Im using: 我正在使用:
Sources: 资料来源:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/931d7bff-90b6-4a70-bb0b-3a097e1301a1/net-40-breaking-change-using-a-markup-extension-as-value-of-property-setter-in-xaml-style?forum=wpf https://social.msdn.microsoft.com/Forums/vstudio/zh-CN/931d7bff-90b6-4a70-bb0b-3a097e1301a1/net-40-breaking-change-using-a-markup-extension-as-value- XAML风格的财产设定者?论坛= wpf
.NET 4.0 Breaking Change - Using a Markup Extension as Value of Property Setter in XAML Style .NET 4.0重大更改-使用标记扩展作为XAML样式的属性设置器的值
{0} is not valid for Setter.Value. {0}对Setter.Value无效。 The only supported MarkupExtension types are DynamicResourceExtension and BindingBase or derived types
唯一受支持的MarkupExtension类型是DynamicResourceExtension和BindingBase或派生类型
On some pages it is said that you should use binding
. 在某些页面上,据说您应该使用
binding
。 But there I got the same error/behavior! 但是我得到了相同的错误/行为!
btw. 顺便说一句 I use this markup extension in a
Storyboard
, so I can't return a binding
anyway. 我在
Storyboard
使用了此标记扩展,因此无论如何我都无法返回binding
。
public override object ProvideValue(IServiceProvider serviceProvider)
{
Binding binding = new Binding();
binding.Source = new SolidColorBrush((Color)ColorConverter.ConvertFromString(Key));
return binding.ProvideValue(serviceProvider);
}
I solved the problem! 我解决了问题! I was a kind of
XAML Resources
relationship. 我是一种
XAML Resources
关系。 I defined a ResourceDictionary
inside of App.xaml
which was already defined in the AssemblyInfo.cs
as a XmlnsPrefix
/ XmlnsDefinition
! 我定义的
ResourceDictionary
内App.xaml
这是已经在规定AssemblyInfo.cs
为XmlnsPrefix
/ XmlnsDefinition
!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.