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

Listbox Image behaviour unexpected

2 Answers 44 Views
ComboBox and ListBox (obsolete as of Q2 2010)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mark Ogle
Top achievements
Rank 1
Mark Ogle asked on 02 May 2010, 04:36 AM
Hi Guys

I have class that inherits RadListBox to implement a menu.

I am loading an image and want to display the text at the left hand side of the item (ListBox cell) and the image at the right hand end.

"i" is a RadListBoxItem:

 i.DisplayStyle = DisplayStyle.ImageAndText;
 i.ImageAlignment = ContentAlignment.MiddleRight;
 i.TextImageRelation = TextImageRelation.TextBeforeImage;
 i.TextAlignment = ContentAlignment.MiddleLeft;
 i.Image = item.Icon;

 Items.Add(i);
 EndInit();

This gives me the image straight after the text. The ImageAlignment property appears to be ignored.

In fact the only property it seems to honor is TextImageRelation

If I pad the text with spaces I can move the graphic across the cell, but this is too imprecise for a generic solution.
I tried experimenting with the AutoSize and AutoSizeMode property to no avail.

What is the best way of achieving this?

Thanks in advance

2 Answers, 1 is accepted

Sort by
0
Accepted
Victor
Telerik team
answered on 05 May 2010, 08:31 PM
Hello Mark Ogle,

Thank you for writing.

This happens because the ImageAndTextLayoutPanel inside RadListBoxItem is measured with its desired size. It's size is as big as the image and the text, and it does not take into account the fact that the parent item is much wider. You can work around this by setting the StretchHorizontally property of the layout panel like this:

(list.Children[2] as ImageAndTextLayoutPanel).StretchHorizontally = true;

Write again if you need further assistance.

Kind regards,
Victor
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Mark Ogle
Top achievements
Rank 1
answered on 06 May 2010, 08:41 AM
Thanks Victor

Completely Solved!
Tags
ComboBox and ListBox (obsolete as of Q2 2010)
Asked by
Mark Ogle
Top achievements
Rank 1
Answers by
Victor
Telerik team
Mark Ogle
Top achievements
Rank 1
Share this question
or