如何在ListBox中水平显示绑定数据

时间:2014-04-25 08:11:51

标签: c# windows-phone

我想在水平模式下使用滚动选项在ListBox中显示集合中的图像。如果我得到了这个(没有滚动),图像会垂直显示。

                <ListBox x:Name="SelectedImages" ItemsSource="{Binding}">
                <ListBox.ItemTemplate>
                     <DataTemplate>
                         <StackPanel Orientation="Horizontal">
                             <Image Source="{Binding Image2}" Height="110" Width="110" />
                         </StackPanel>
                     </DataTemplate>
                 </ListBox.ItemTemplate>
                 </ListBox>

如果我试试这个,我的屏幕就是空白。

                <ListBox x:Name="SelectedImages" ItemsSource="{Binding}">
                     <ListBox.ItemsPanel>
                          <ItemsPanelTemplate>
                               <StackPanel Orientation="Horizontal" />
                          </ItemsPanelTemplate>
                     </ListBox.ItemsPanel>

                     <ListBox.ItemTemplate>
                         <DataTemplate>
                             <StackPanel Orientation="Horizontal">
                                <Image Source="{Binding Image2}" Height="110" Width="110" />
                             </StackPanel>
                         </DataTemplate>
                    </ListBox.ItemTemplate>
            </ListBox>

1 个答案:

答案 0 :(得分:1)

<ListBox x:Name="SelectedImages"  ScrollViewer.HorizontalScrollBarVisibility="Auto">
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Horizontal" />
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
    <ListBox.ItemTemplate>
        <DataTemplate>
        <StackPanel Orientation="Horizontal">
        <Image Source="{Binding Image2}" Height="110" Width="110" />
         </StackPanel>
        </DataTemplate>
      </ListBox.ItemTemplate>
</ListBox>