当前位置: 代码迷 >> Silverlight >> 6个小时未搞定的横向排列+纵向排列,含泪向CSDN
  详细解决方案

6个小时未搞定的横向排列+纵向排列,含泪向CSDN

热度:1165   发布时间:2013-02-26 00:00:00.0
6个小时未搞定的横向排列+纵向排列,含泪向CSDN求救
测试文字!测试文字!测试文字!测试文字!
测试文字!测试文字!测试文字!测试文字!
测试文字!测试文字!测试文字!
===============================================
要实现上述横向排列并自动换行,不要产生横向的滚动条,如何实现呢
我用listbox+WrapPanel,结果它总是横向一排或者纵向一排
代码如下

<UserControl.Resources>
<ItemsPanelTemplate x:Key="ItemsPanelTemplate1">
<controlsToolkit:WrapPanel Width ="100" HorizontalAlignment="Left"/>
</ItemsPanelTemplate>
</UserControl.Resources>
  <Grid x:Name="LayoutRoot">

        <ListBox x:Name="myListBox" HorizontalAlignment="Left" Margin="50,66,0,49" Width="350" ItemsPanel="{StaticResource ItemsPanelTemplate1}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock x:Name="name" Text="{Binding mydesc}"></TextBlock>
                        <Image x:Name="image" Source="{Binding mysource}" Width="100" Height="50"></Image>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>

后台代码我就不给了,数据源是没问题的
------解决方案--------------------------------------------------------
不知道是不是楼主想要的。这样貌似是可以的。

    <navigation:Page.Resources>
        <ItemsPanelTemplate x:Key="ItemsPanelTemplate1">
                <controlsToolkit:WrapPanel/>
        </ItemsPanelTemplate>

    </navigation:Page.Resources>
  <Grid x:Name="LayoutRoot">
        <ListBox x:Name="myListBox" HorizontalAlignment="Left" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Margin="50,66,0,49" Width="350" ItemsPanel="{StaticResource ItemsPanelTemplate1}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock x:Name="name" Text="{Binding Text}"></TextBlock>
                    </StackPanel>
                </DataTemplate>
  相关解决方案