【问题标题】:Images in a Horizontal StackPanel are being displayed Vertically水平 StackPanel 中的图像垂直显示
【发布时间】:2011-03-11 07:17:38
【问题描述】:

我正在 Silverlight 4 中构建布局,并尝试使用水平滚动条水平显示一些缩略图图像。为此,我尝试使用具有水平方向的 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

【问题讨论】:

    标签: silverlight silverlight-4.0 stackpanel


    【解决方案1】:

    与其尝试自己管理ScrollViewer(ListBox 已经这样做了),您只需将默认的ItemsPanel 替换为Horizo​​ntal StackPanel。像这样:-

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-18
      • 1970-01-01
      相关资源
      最近更新 更多