nan
nan

Reputation: 585

WPF Binding on DependencyObject error

I want to pass an object as a parameter to a Converter. Since I can't do that using a ConverterParameter, I have used a DependencyProperty instead.

Here is the code -

public class FilteredColumnConverter : DependencyObject, IValueConverter
{
     public DataGridFilter FilterObject
     {
         get { return (DataGridFilter) GetValue(FilterObjProperty); }
         set { SetValue(FilterObjProperty, value); }
     }

     public static readonly DependencyProperty FilterObjProperty =
     DependencyProperty.Register( "FilterObj",
     typeof(DataGridFilter),
     typeof(FilteredColumnConverter),
     new PropertyMetadata(null));

     // With implementations for Convert and ConvertBack
}

My XAML:

<UserControl.Resources> 
     <helpers:FilteredColumnConverter x:Key="filteredColumnConverter"
              FilterObject="{Binding myFilterObj}"/>
</UserControl.Resources>

I'm getting the following error :

A Binding cannot be set on the FilterObject property of type FilteredColumnConverter. A Binding can only be set on a DependencyProperty of a DependencyObject.

What seems to be the problem? I have a FilterObject is a dependency property and I have followed the naming conventions as well.

Upvotes: 0

Views: 1036

Answers (1)

ASh
ASh

Reputation: 35720

try register DP with name FilterObject not FilterObj

DependencyProperty.Register("FilterObject", ...

Upvotes: 1

Related Questions