I have a custom MarkupExtension that mimics a binding. It works well in ordinary applications, but when used in Style Setters, for example:
<Setter Property="Content" Value="{local:MyExtension}" />
throws a XamlParseException:
A 'Binding' cannot be set on the 'Value' property of type 'Setter'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.
This is an implementation of the extension:
public class MyExtension : MarkupExtension { public MyExtension() { Value = 123; } public object Value { get; set; } public override object ProvideValue(IServiceProvider serviceProvider) { var binding = new Binding("Value") { Source = this, }; return binding.ProvideValue(serviceProvider); } }
What a problem ?!
source share