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

ListBox Template - Layout Doesn't Work

1 Answer 185 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Robert
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:

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



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

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.

Rob

1 Answer, 1 is accepted

Sort by
0
George
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" />
</Style>

Hope this helps.

Greetings,
George
the Telerik team

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

Tags
ListBox
Asked by
Robert
Top achievements
Rank 1
Answers by
George
Telerik team
Share this question
or