Mysterious Null Data Type for DependencyProperty RRS feed

  • Question

  • While changing some code in a windows store app that I have built I ran into a crippling error which is the following:

    "Error: Converter failed to convert value of type 'Display.MatrixDisplay.Dimensions, Display, Version=, Culture=neutral, PublicKeyToken=null' to type '(null)'; BindingExpression: Path='Dimensions' DataItem='MatrixApp2.ViewModel.ResizeableMatrixViewModel, MatrixApp2, Version=, Culture=neutral, PublicKeyToken=null'; target element is 'Display.MatrixDisplay.ResizeableMatrix, Display, Version=, Culture=neutral, PublicKeyToken=null' (Name='null'); target property is 'Dimensions' (type '(null)'). "

    Normally a binding failure message leads to some small mistake that was made, but here it is trying to tell me that the type of my dependencyproperty Dimensions is null, which is exceedingly odd. The actual type is Dimensions (same name as the dependencyproperty, I tried changing the name of the type to DimensionsX just to check if for some weird reason it had to do with both having the same name, but that didn't change anything). After messing around, I found that by changing the type to a basic type (such as double) the binding works just fine, so for some reason the dependencyproperty doesn't like the type Dimensions. The way that the code works right now is that the DataContext of a component that has a ResizeableMatrix is set to an instance of ResizeableMatrixViewModel (this all works perfectly unless the binding to Dimensions is included, which are the first two lines in the constructor for ResizeableMatrix).

    The code for my Dimensions class is as follows:

    public class Dimensions : BindableBase
        private int _rows = 0;
        public int Rows
            get { return this._rows; }
            set { this.SetProperty<int>(ref this._rows, this._rows); }
        private int _columns = 0;
        public int Columns
            get { return this._columns; }
            set { this.SetProperty<int>(ref this._columns, this._columns); }
        public Dimensions(int rows, int columns)
            this._rows = rows;
            this._columns = columns;

    and the code for the ResizeableMatrix class where the dependencyproperty is defined is:

    public class ResizeableMatrix : MatrixVisualBase
            public static readonly DependencyProperty EntryDimensionProperty = DependencyProperty.Register("EntryDimension", typeof(double), typeof(ResizeableMatrix), new PropertyMetadata(10.0, InvalidateMeasure_Callback));
            public static readonly DependencyProperty DimensionsProperty = DependencyProperty.Register("Dimensions", typeof(Dimensions), typeof(ResizeableMatrix), new PropertyMetadata(new Dimensions(1, 1), InvalidateMeasure_Callback));
            public ResizeableMatrix()
                Binding dimensionsBinding = new Binding() { Path = new PropertyPath("Dimensions"), Mode = BindingMode.OneWay };
                this.SetBinding(ResizeableMatrix.DimensionsProperty, dimensionsBinding);
                Binding entryDimensionBinding = new Binding() { Path = new PropertyPath("EntryDimension") };
                this.SetBinding(ResizeableMatrix.EntryDimensionProperty, entryDimensionBinding);
            private static void InvalidateMeasure_Callback(DependencyObject d, DependencyPropertyChangedEventArgs e)
                ResizeableMatrix rm = (ResizeableMatrix)d;
            protected override Size MeasureInterior(Size availableSize)
                Dimensions dimensionsValue = (Dimensions)(this.GetValue(DimensionsProperty));
                double entryDimensionValue = (double)(this.GetValue(EntryDimensionProperty));
                return new Size(dimensionsValue.Columns * entryDimensionValue, dimensionsValue.Rows * entryDimensionValue);
            protected override Size ArrangeInterior(Point upperLeft, Size finalSize)
                return finalSize;

    and the code for the ResizeableMatrixViewModel is:

    public class ResizeableMatrixViewModel : MatrixDisplayModel
            private Dimensions _dimensions;
            public Dimensions Dimensions
                get { return this._dimensions; }
                set { this.SetProperty<Dimensions>(ref this._dimensions, value); }
            private double _entryDimension;
            public double EntryDimension
                get { return this._entryDimension; }
                set { this.SetProperty<double>(ref this._entryDimension, value); }
            public ResizeableMatrixViewModel()
                : base(typeof(ResizeableMatrix))
            { }

    Any help would be greatly appreciated. I am very stumped as to why winrt is making the type of my dependencyproperty null instead of Dimensions.

    Wednesday, November 13, 2013 2:18 AM

All replies

  • Hi,

    Can you upload your project in SkyDrive and share a link in the forum! lt is difficult to make sure

    why the problem occurs.

    Best Wishes!

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Edited by Anne Jing Thursday, November 14, 2013 9:10 AM edit
    Thursday, November 14, 2013 9:10 AM