WPF Listbox Wrapping

回眸只為那壹抹淺笑 提交于 2019-12-04 18:35:38

问题


I have a listbox in which I use a ListBox.ItemsPanel - WrapPanel.

<ListBox ItemsSource="{Binding Path=Applets}" Margin="10,92,10,10" ScrollViewer.HorizontalScrollBarVisibility="Disabled" >

        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>

                <WrapPanel Orientation="Vertical" IsItemsHost="True">

                </WrapPanel>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>



        <ListBox.ItemTemplate>...

I am trying to have the wrappanel have a behavior such that the items fill in to the right as the width is made wider and wrap as needed when the window is made narrower. I have played with it but the correct combination eludes me. Does anyone have a suggestion?

My next goal would be able to reorder/ sort the items and have the render update.

TIA


回答1:


I am trying to have the wrappanel have a behavior such that the items fill in to the right as the width is made wider and wrap as needed when the window is made narrower. I have played with it but the correct combination eludes me. Does anyone have a suggestion?

The code you have is almost correct, just change the Orientation to Horizontal and it should work as you describe

My next goal would be able to reorder/ sort the items and have the render update.

You don't have to do anything special for that, it's the normal behavior of a ListBox. Just change the sort order (using ICollectionView.SortDescriptions), and the UI will reflect the changes




回答2:


                <ListBox Grid.Row="1" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                <ListBoxItem Name="lbiTmp3_1"><CheckBox>
                        <TextBlock TextWrapping="Wrap">
                        lkjfd gmlkdsfmlk gmdsgf  kds lkjglfdjmlkg jfdsg dsgf lkhfdgs lkjds fg
                    </TextBlock></CheckBox>
                </ListBoxItem>
                <ListBoxItem Name="lbiTmp3_2">C0ucou</ListBoxItem>
                <ListBoxItem Name="lbiTmp3_3">C0ucou</ListBoxItem>
            </ListBox>


来源:https://stackoverflow.com/questions/4139580/wpf-listbox-wrapping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!