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

ListBox Template - Layout Doesn't Work

1 Answer 113 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Robert asked on 01 May 2012, 11:55 AM
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.


1 Answer, 1 is accepted

Sort by
Telerik team
answered on 04 May 2012, 07:31 AM
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 >>

Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question