0

I know it's simple but I spent a lot of time to display my the list horizontally. I even put the make StackPanel orientation "Horizontal" but all in vain. Can anyone help with this? I would really appreciate that.

<Window x:Class="RssFeed_Wpf.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:RssFeed_Wpf"
    mc:Ignorable="d"
    Title="MainWindow" Height="350" Width="525">
<Window.Resources>
    <XmlDataProvider x:Key="DataRss" XPath="//item" Source="http://www.abc.net.au/news/feed/52278/rss.xmlhttp://www.abc.net.au/news/feed/45910/rss.xml">
    </XmlDataProvider> 
</Window.Resources>
    <ListBox ItemsSource="{Binding Source = {StaticResource DataRss}}" Background="Black" HorizontalContentAlignment="Left" BorderBrush="Transparent">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{Binding XPath=title}" FontWeight="Bold" Name="txtScrolling" FontFamily="calibri"  Foreground="#f4b042" Height="20pt">
                    </TextBlock>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
 </Window>

You can see here, The list is shown vertically but I want this horizontally:

Screenshot

Manfred Radlwimmer
  • 13,257
  • 13
  • 53
  • 62

1 Answers1

1

Because your StackPanel is in the DataTemplate there is a StackPanel created for every item in the ListBox. To change the container for the ListBox you need to sets it ItemsPanel

<ListBox >
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Horizontal"/>
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
</ListBox>
Tim Rutter
  • 4,549
  • 3
  • 23
  • 47