Does Catel support binding to indexer property?

May 6, 2011 at 10:35 AM

Does Catel support binding to indexer property?

Coordinator
May 6, 2011 at 11:48 AM

Catel does not create bindings on it's own. For bindings it uses the WPF (or SL or WP7) way of binding.

What exactly do you mean with "binding to indexer property"? If you give me an example, I'll show you a way how to deal with it.

May 6, 2011 at 2:10 PM
Edited May 6, 2011 at 2:13 PM

 

    public class Aligner4
    {
        public Aligner4()
        {
            this.alignerValue = new DoubleParameter[(Int32)Aligner4PolePair.TotalCount];
            Int32 i;
            for (i = 0; i < (Int32)Aligner4PolePair.TotalCount; i++)
            {
                this.alignerValue[i] = new DoubleParameter();
            }
            this.TiltFactor = 1.0;
        }

        public void CalculateTiltFactor(Double tiltRange = 100.0)
        {
               ...
        }

        public DoubleParameter[] alignerValue;

        public Double TiltFactor { get; set; }

        public Boolean Enable
        {
            get
            {

            }
            set
            {

            }
        }

        public Double TiltX
        {
            get
            {
                return this[Aligner4PolePair.PoleX] / this.TiltFactor;
            }
            set
            {
                this[Aligner4PolePair.PoleX] = this.TiltFactor * value;
            }
        }

        public Double TiltY
        {
            get
            {
                return this[Aligner4PolePair.PoleY] / this.TiltFactor;
            }
            set
            {
                this[Aligner4PolePair.PoleY] = this.TiltFactor * value;
            }
        }

        public Double this[Int32 index, DoubleParameterType parameterType = DoubleParameterType.ParameterValue]
        {
            get
            {
                switch (parameterType)
                {
                    case DoubleParameterType.ParameterValue:
                        return this.alignerValue[index].Value;
                    case DoubleParameterType.ParameterValueMax:
                        return this.alignerValue[index].ValueMax;
                    case DoubleParameterType.ParameterValueMin:
                        return this.alignerValue[index].ValueMin;
                    case DoubleParameterType.EnableFlag:
                        if (this.alignerValue[index].ParameterEnable)
                        {
                            return 1.0;
                        }
                        else
                        {
                            return 0.0;
                        }
                }
                return Double.NaN;
            }
            set
            {
                switch (parameterType)
                {
                    case DoubleParameterType.ParameterValue:
                        this.alignerValue[index].Value = value;
                        break;
                    case DoubleParameterType.ParameterValueMax:
                        this.alignerValue[index].ValueMax = value;
                        break;
                    case DoubleParameterType.ParameterValueMin:
                        this.alignerValue[index].ValueMin = value;
                        break;
                    case DoubleParameterType.EnableFlag:
                        this.alignerValue[index].ParameterEnable = (value != 0.0);
                        break;
                }
            }
        }
    }


If we'd like to convert above class into Catel DataObjectBase, we can easily convert "TiltFactor", "Enable", "TiltX", "TiltY" into DataObjectBase-properties
but I don't know how to convert the indexer property "this[Int32 index, DoubleParameterType parameterType = DoubleParameterType.ParameterValue]" because it
does not have a string name. I tried to use "Item" but it seems it doesn't work.
Coordinator
May 7, 2011 at 7:58 AM

An indexer is not a property of a class, it's an operator. Therefore, it cannot be serialized on it's own. You will need to declare a property that holds a collection of items (private if you wish), and in the indexer just use that collection to return the aligner value.