1

I want to have the ListItems to extend with their Stackpanel the full width of the Listbox.

Currently they are only as wide as the textblocks.

What do I have to do so that the Stackpanel of the ListBoxItems fill the width of the ListBox?

            <ListBox Name="feedListBox" VerticalAlignment="Top" ScrollViewer.VerticalScrollBarVisibility="Auto" SelectionMode="Single" SelectionChanged="feedListBox_SelectionChanged">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock FontFamily="Segoe UI Symbol" Text="&#x26FD;"  FontSize="25"/>
                        <StackPanel Orientation="Vertical">
                            <TextBlock Name="txtDate" Text="{Binding Date}" FontSize="15" Margin="20,0,0,0"/>
                            <TextBlock Name="txtDitance" Text="{Binding Distance}" FontSize="15" Margin="20,5,0,0"/>
                        </StackPanel>
                        <TextBlock Name="txtPrice" Text="{Binding Price}" FontSize="15" Margin="30,0,0,0"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
radin
  • 251
  • 3
  • 16
  • HorizontalContentAlignment="Stretch" on your ListBox doesn't do it? – Chris W. Nov 02 '15 at 17:02
  • @ChrisW. No! it doesn't do it! – radin Nov 02 '15 at 17:23
  • What about setting at the ItemContainer like the 2nd answer [here](http://stackoverflow.com/questions/838828/how-to-get-a-listbox-itemtemplate-to-stretch-horizontally-the-full-width-of-the) which would work in SL which is often similar to the win10 stuff. – Chris W. Nov 02 '15 at 18:39
  • Tried new Universal app with your ListBox and it's setting it's items size as expected, and as you wanted them. My thoughts are maybe you have some other style overriding, or some other element is breaking something. Maybe try with new project and if it works start removing things that might interfere one by one until it works in the original project. – kirotab Nov 02 '15 at 20:43
  • @kirotab thank you! I delete VerticalAlignment="Top" and its work :D – radin Nov 03 '15 at 05:38
  • Hm, strange, but if it works - great :) – kirotab Nov 03 '15 at 06:52

1 Answers1

0

delete: VerticalAlignment="Top" and use: HorizontalContentAlignment="Stretch"

radin
  • 251
  • 3
  • 16