This is a migrated thread and some comments may be shown as answers.

Size is always 0 on LightVisualElement

2 Answers 107 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Tomas
Top achievements
Rank 1
Tomas asked on 11 Apr 2017, 03:52 AM
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 Answers, 1 is accepted

Sort by
0
Tomas
Top achievements
Rank 1
answered on 11 Apr 2017, 04:07 AM

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.

0
Hristo
Telerik team
answered on 11 Apr 2017, 02:55 PM
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.
Tags
General Discussions
Asked by
Tomas
Top achievements
Rank 1
Answers by
Tomas
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or