I need to define DependencyProperty in the converter class, because I need this data to do the conversion, and this data is in a different object, and not the one with which I am attached.
My converter class is as follows:
public class LEGOMaterialConverter : DependencyObject, IValueConverter { public DependencyProperty MaterialsListProperty = DependencyProperty.Register("MaterialsList", typeof(Dictionary<int, LEGOMaterial>), typeof(LEGOMaterialConverter)); public Dictionary<int, LEGOMaterial> MaterialsList { get { return (Dictionary<int, LEGOMaterial>)GetValue(MaterialsListProperty); } set { SetValue(MaterialsListProperty, value); } } public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { LEGOMaterial material = null; MaterialsList.TryGetValue((int)value, out material); return material; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } }
Then I run it in the Window.REsources area:
<Window.Resources> <local:LEGOMaterialConverter x:Key="MaterialsConverter" MaterialsList="{Binding Path=Materials}" /> </Window.Resources>
I get the following error:
'MaterialsList' property was already registered by 'LEGOMaterialConverter'.
Does anyone know this error?
source share