简体   繁体   中英

3 Column ListBox in Silverlight for Wp7

I'm really going mad ... but the whole evening I'm trying to create a 3 column listbox. I want that the 3 columns are spread over the whole size of the listbox and not sticked together like they do when using the code below.

So, here's my XML

<ListBox Background="Red" HorizontalContentAlignment="Stretch"
         ItemsSource="{Binding ListItems}"
         >

    <ListBox.ItemTemplate>
        <DataTemplate>
            <Grid HorizontalAlignment="Stretch" Background="Aquamarine">

                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>

                <TextBlock Grid.Column="0" Text="A"/>
                <TextBlock Grid.Column="1" Text="B"/>
                <TextBlock Grid.Column="2" Text="C"/>
            </Grid>        
        </DataTemplate>            
    </ListBox.ItemTemplate>

</ListBox>

Hope you can help me.

If you set the Width attribute of a ColumnDefinition to Auto that column will only use the minimum required width. Change the width of all 3 columns to * .

Also try setting the HorizontalAlignment attribute of the 3 TextBlock s to Center .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM