Listbox Image behaviour unexpected

3 posts, 1 answers
  1. Mark Ogle
    Mark Ogle avatar
    4 posts
    Member since:
    Jun 2008

    Posted 01 May 2010 Link to this post

    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. Answer
    Victor
    Admin
    Victor avatar
    1351 posts

    Posted 05 May 2010 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Mark Ogle
    Mark Ogle avatar
    4 posts
    Member since:
    Jun 2008

    Posted 06 May 2010 Link to this post

    Thanks Victor

    Completely Solved!
Back to Top