I have a custom MarkupExtension that simulates binding. It works well in normal assignments but when used in Style Setters, for example:
From the documentation, it looks like the object must be freezable (so they can be shared between various interested parties)
http://msdn.microsoft.com/en-us/library/system.windows.setter.value.aspx
"Data binding and dynamic resources within the object is supported if the specified value is a Freezable object. See Binding Markup Extension and DynamicResource Markup Extension."
why don't you
return Value
inside the ProvideValue??
You can bind to only DependencyProperty. make a dependency property for Value in your MyExtension Class!
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(Object), typeof(MyContentControl), new UIPropertyMetadata());
Kind of guessing, but it's likely because the XAML compiler has special built-in support for the Binding class, allowing its usage in this scenario (and others). The Binding class is also a MarkupExtension, but unfortunately it seals its implementation of ProvideValue().
That said, you might just get away with this:
public class MyBinding : Binding
{
private object value;
public object Value
{
get { return this.value; }
set
{
this.value = value;
this.Source = value;
}
}
}
Since ProvideValue will return the Binding instance anyway.