MarkupExtension with binding parameters

binding, wpf

Solution

A 'Binding' can only be set on a DependencyProperty of a DependencyObject - it is true. The problem is that `MarkupExtension` class does not derive from `DependencyObject`, that's why it is not possible to set binding on it's properties.

[EDIT]

Workaround is using ValueConverters. Another workaround is to change C# language to allow multiple inheritance. By the way, in Silverlight `MarkupExtension` implements `IMarkupExtension` interface, so I tried to implement it in my custom extension and derive it from `DependecyObject`, added `DependencyProperty` there and set binding to it. It doesn't crash, but the binding is actually set after ProvideValue() is called. So even in Silverlight there's no solution (or it is difficult - see link provided in Klaus78's answer). In WPF MarkupExtension doesn't implement any interface, so you cannot bind to it's properties.

Problem

I am working on a custom `MarkupExtension` in which I need a non string parameters from XAML to construct the new object. Is it possible to use a non-string parameter binding on a field in `DataContext` scope? In other words, how can I do something like this? ``` <ListBox ItemsSource="{Binding Source={local:MyMarkupExtension {x:Type Button},IncludeMethods={Binding Source=CustomerObject.IsProblematic}}}" /> ``` where `IncludeMethods=CustomerObject.IsProblematic` give me this error: Binding cannot be set on the 'IncludeMethods' property of type 'TypeDescriptorExtension'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject. Can anyone help me? thanks

Original source

Related problems