Below is a very small example how to get this exception
. This is already a known issue (for more than 7 years!). Is there already a solution for that?
FooExtension is not valid for Setter.Value. The only supported MarkupExtension types are
DynamicResourceExtension and BindingBase or derived types.
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.
Background="{extensions:Foo Key=#FFF37C21}"
The extension
worked until yesterday for more than 1 year! Including every Windows, VisualStudio or any other update! And now since 1 day I got this bug behavior during the design time!
Im using:
Sources:
.NET 4.0 Breaking Change - Using a Markup Extension as Value of Property Setter in XAML Style
{0} is not valid for Setter.Value. The only supported MarkupExtension types are DynamicResourceExtension and BindingBase or derived types
On some pages it is said that you should use 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.
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. I defined a ResourceDictionary
inside of App.xaml
which was already defined in the AssemblyInfo.cs
as a XmlnsPrefix
/ XmlnsDefinition
!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.