Alignment in GridLayout

1 Answer 265 Views
LayoutControl
Holger
Top achievements
Rank 1
Holger asked on 08 Apr 2022, 10:46 AM

When Adding a Label in a GridLayout


var element = new RadLabelElement()
 element.SetValue(GridLayout.ColSpanProperty, colspan);
            element.SetValue(GridLayout.RowIndexProperty, row);
            element.SetValue(GridLayout.ColumnIndexProperty, column);
How do I achieve to right align, or center the label, especially when it spans multiple columns.

(If I could get the label to fill the entire cell, I could use the TextAlignment proproperty, but with Autosize enabled, it will never fill the entire cell.)

 

 

1 Answer, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 13 Apr 2022, 07:33 AM

Hello Holger,

Thank you for your interest in our GridLayout panel.

I have tested your scenario but it seems that I was able to move the label element to the right side by setting the TextAlignment property. You can find the sample project which I used to test your case. When you run the project you can observe how the label is placed on the bottom right side. May I ask you to take a look at the project and let me know what I am missing from your setup?

Regards,
Dinko
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Holger
Top achievements
Rank 1
commented on 21 Apr 2022, 10:30 AM

Thanks for the support.
Actually it's the default setting of StretchVertically=true and StretchHorizontally=true in the Element, what completly 'disables' the AutoSize, and if the Label ist filling the cell completly, of course the TextAlignment does work.

For myself, I found a more general solution, not just for Labels.

Any RadElement has an Alignment property for positioning inside the Parent Element, this also works for GridLayout-Cells.

So for unstretched elements it's just:


            element.StretchVertically = false;
            element.StretchHorizontally = false;
            element.Alignment = ContentAlignment.BottomRight;

It's just my inexperience, not to know this in advance, but you inspired my research. Thanks.

 

Dinko | Tech Support Engineer
Telerik team
commented on 22 Apr 2022, 08:43 AM

I am happy that you have found a solution for your scenario and thank you for sharing it. If you have any further questions, you can open a new thread with your questions inside and we will be happy to help.
Tags
LayoutControl
Asked by
Holger
Top achievements
Rank 1
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or