Click here to Skip to main content
15,897,291 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I would convert the text below (c#) in IronPython.
I need create a DrawingVisual and I must override the VisualChildrenCount property and the GetVisualChild method.

source: official web Microsoft

C#
// Provide a required override for the VisualChildrenCount property.
        protected override int VisualChildrenCount
        {
            get { return _children.Count; }
        }

        // Provide a required override for the GetVisualChild method.
        protected override Visual GetVisualChild(int index)
        {
            if (index < 0 || index >= _children.Count)
            {
                throw new ArgumentOutOfRangeException();
            }

            return _children[index];
        }


What I have tried:

Python
class MyVisualHost(FrameworkElement):

    def __init__(self, drawingVisual):

        self._children = VisualCollection(self)
        self._children.Add(drawingVisual)

        self.VisualChildrenCount = self._children.Count

        def GetVisualChild(self, index):
            try:
                if (index <= 0) or (index >= _children.Count):

                     System.ArgumentOutOfRangeException()

                else:
                    return _children[index]
            except:
                pass

myVisualHost = MyVisualHost(drawingVisual)

Message:Expected property for VisualChildrenCount, but found int.

Any suggestions?, thanks
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900