首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > CAD教程 >

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

2013-01-08 
6个小时未搞定的横向排列+纵向排列,含泪向CSDN求救测试文字!测试文字!测试文字!测试文字!测试文字!测试文

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>


            </ListBox.ItemTemplate>
        </ListBox>
        <Button Content="click" Click="Button_Click" Height="10" Width="10"></Button>
    </Grid>


[解决办法]
TextWrapping="Wrap"添加这个属性就可以了。
不会产生滚动条了。
完整的例子

<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} TextWrapping="Wrap""></TextBlock>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <Button Content="click" Click="Button_Click" Height="10" Width="10"></Button>
    </Grid>

[解决办法]
在listbox中加 ScrollViewer.HorizontalScrollBarVisibility="Disabled" 试试。。

热点排行