2010-07-02 84 views
1

我在Silverlight 4中構建了一個佈局,並試圖用水平滾動條水平顯示一些縮略圖。爲此,我嘗試使用水平方向的StackPanel,但結果圖像始終垂直顯示。垂直顯示水平StackPanel中的圖像

<ScrollViewer Height="140" VerticalAlignment="Top" VerticalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Auto"> 
    <StackPanel Height="140" Orientation="Horizontal"> 
     <ListBox Height="140" ItemsSource="{Binding SelectedUser.ProfileImages}" /> 
    </StackPanel> 
</ScrollViewer> 

ItemsSource是System.Windows.Controls.Image的列表。爲了測試,我使用4個縮略圖播種它,並將尺寸設置爲120x160。

BitmapImage bmpImage1 = new BitmapImage { UriSource = new Uri("Style/Images/thumbnail1.jpg", UriKind.Relative) }; 
Image image1 = new Image { Source = bmpImage1, Height = 120, Width = 160 }; 

生成的頁面對象最終看起來像下面鏈接的圖像。高度140,寬度160,但圖像垂直排列而不是水平排列。任何想法如何讓這些圖像水平顯示而不是垂直顯示?

http://img824.imageshack.us/img824/8211/stackpanel.png

回答

1

而不是你自己(這ListBox中已經這樣做了),試圖經理ScrollViewer你只需要與水平StackPanel替換默認ItemsPanel。像這樣: -

<ListBox Height="140" ItemsSource="{Binding SelectedUser.ProfileImages}"> 
    <ListBox.ItemsPanel> 
    <ItemsPanelTemplate> 
     <StackPanel Orientation="Horizontal" /> 
    </ItemsPanelTemplate> 
    </ListBox.ItemsPanel> 
</ListBox>