ListBox Template - Layout Doesn't Work

2 posts, 0 answers
  1. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 01 May 2012 Link to this post

    Good morning,

    I'm having trouble with the RadListBox Template. For some reason if I insert a grid into a listbox template its formatting is not preserved.

    Here's my code:

    <DataTemplate x:Key="AutoCompleteListBoxTemplate">
        <Grid Width="{Binding ElementName=radListBox, Path=Width}">
                <ColumnDefinition  />
                <ColumnDefinition />
            <TextBlock Text="{Binding Name}" Grid.Column="0" HorizontalAlignment="Stretch"   />
            <TextBlock Text=">>" Grid.Column="1" HorizontalAlignment="Right" Margin="5,0,5,0" />

    <telerik:RadListBox MinWidth="100" MaxHeight="250" x:Name="radListBox"
                        Grid.ColumnSpan="2" Visibility="Collapsed"
                        HorizontalAlignment="Left" VerticalAlignment="Top"
                        ItemTemplate="{StaticResource AutoCompleteListBoxTemplate}"
            <DropShadowEffect ShadowDepth="10" Color="Gray" Opacity=".4" Direction="320" RenderingBias="Performance" />

    You will notice that in my template I have grid where I'm trying to force the last column over to the far right of the ListBoxItem. For some reason this isn't working with both columns aligning to the left. If I build the grid not within a ListBox template then it works.
    I'm trying to make the last grid items align no matter the length of the content in the column before it.

    Could the cause be that I'm using the Office_BlueTheme()?

    ****** EDIT ********
    I tried removing the theme but it doesn't make a difference.

    Thank you for your time.

  2. George
    George avatar
    1332 posts

    Posted 04 May 2012 Link to this post

    Hello Rob,

    The default HorizontalContentAlignment value for the RadListBoxItems is Left, but you want to make it stretch. Please, correct me if I am wrong. In order to accomplish this scenario, I would suggest using the following style:

    <Style TargetType="telerik:RadListBoxItem">
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />

    Hope this helps.

    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top