Size is always 0 on LightVisualElement

3 posts, 0 answers
  1. Tomas
    Tomas avatar
    2 posts
    Member since:
    Apr 2017

    Posted 10 Apr 2017 Link to this post

    I have an Element that Inherits from LightVisualElement. In CreateChildElements I add three controls - StackLayoutPanel, Image and Label - however the Size is always 0 which causes problems in another controller where I try to stack several Elements together.

     

    Why is the Size 0?

    When is the Size initialized?

     
    protected override void CreateChildElements()
            {
                base.CreateChildElements();
     
                mainPanel = new StackLayoutPanel();
                mainPanel.Orientation = System.Windows.Forms.Orientation.Horizontal;
     
                checkBox = new LightVisualElement();
                checkBox.DrawText = false;
                checkBox.ImageLayout = System.Windows.Forms.ImageLayout.Center;
                checkBox.ShouldHandleMouseInput = false;
                checkBox.NotifyParentOnMouseInput = true;
     
                mainPanel.Children.Add(checkBox);
     
                label = new RIOLabelElement();
                label.TextAlignment = ContentAlignment.TopCenter;
                label.Font = new System.Drawing.Font("Segoe UI", 8, FontStyle.Italic, GraphicsUnit.Point);
                label.ShouldHandleMouseInput = false;
                label.NotifyParentOnMouseInput = true;
                mainPanel.Children.Add(label);
                 
                this.Children.Add(mainPanel);
            }
  2. Tomas
    Tomas avatar
    2 posts
    Member since:
    Apr 2017

    Posted 10 Apr 2017 Link to this post

    Couldn't find the Edit button so I will add a reply:

    I tried using AutoSize = true on the panel as well as all the elements but with no luck.

    The goal is to get the correct size when calling this.Size or when calling the Element from another controller/class.

  3. Hristo
    Admin
    Hristo avatar
    1508 posts

    Posted 11 Apr 2017 Link to this post

    Hi Thomas,

    Thank you for writing.

    The CreateChildElements method is intended to be used for the initialization of children added to the custom element. At that point, the layout has not passed and the returned size will be empty. You handle the PropertyChanged event as per my snippet below which I hope would fit your local setup: 
    protected override void CreateChildElements()
    {
        base.CreateChildElements();
     
        //...
     
        this.PropertyChanged += CustomGridDataCellElement_PropertyChanged;
    }
     
    private void CustomGridDataCellElement_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
    {
        if (e.PropertyName == "Bounds")
        {
            this.PropertyChanged -= CustomGridDataCellElement_PropertyChanged;
            Size size = this.Size;
            //...
        }
    }

    I hope this helps. Please let me know if you need further assistance.

    Regards,
    Hristo
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top