WPF ListView中始终显示完整的项目 [英] WPF ListView Always show complete items

查看:179
本文介绍了WPF ListView中始终显示完整的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个时,ListView控件的应用程序,其中有该项目的ListView中必须清晰可见的要求。有不应该在列表中的部分的ListViewItem的表现。如果用户释放的ScrollViewer在那个最终呈现出部分项目,然后在列表应该快照,这样只显示完整的项目自行纠正的位置。

有没有人这样做呢?我想我会需要重载ListView和/或ScrollViewer中做到这一点。我在找对如何处理这一建议。谢谢你。

下面是我的列表中的一个:

 < ctrls监视:果snaplist X:NAME =PART_ProductList
                                            ScrollViewer.CanContentScroll =假
                                            ScrollViewer.VerticalScrollBarVisibility =自动
                                            ScrollViewer.Horizo​​ntalScrollBarVisibility =隐藏
                                            ItemContainerStyle ={StaticResource的ProductFinderItem}
                                            Canvas.Top =373Canvas.Left =75
                                            HEIGHT =910WIDTH =900>                            < ctrls监视:SnapList.ItemsPanel>
                                    < ItemsPanelTemplate>
                                        < VirtualizingStackPanel VirtualizingStackPanel.IsVirtualizing =真VirtualizingStackPanel.VirtualizationMode =标准/>
                                < / ItemsPanelTemplate>
                            < / ctrls监视:SnapList.ItemsPanel>                            < ctrls监视:SnapList.Template>
                                    <&控件模板GT;
                                    <的ScrollViewer X:NAME =滚轮VerticalAlignment =评出的CanContentScroll =真风格={StaticResource的VertScrollViewer}调焦=false的>
                                                <项目presenter />
                                            < /&的ScrollViewer GT;
                                    < /控件模板>
                            < / ctrls监视:SnapList.Template>
                        < / ctrls监视:果snaplist>


解决方案

我相信你正在寻找的<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.controls.scrollviewer.cancontentscroll.aspx\"相对=nofollow> ScrollViewer.CanContentScroll 地产

如果您知道在ListView项目的最大尺寸,确保ListView的高度是一样的大小,或者该项目高度的倍数。

工作示例:

 &LT; ListView控件ScrollViewer.CanContentScroll =真
            HEIGHT =200&GT;    &LT; ListBoxItem的高度=50
                    CONTENT =测试1/&GT;
    &LT; ListBoxItem的高度=50
                    CONTENT =Test2的/&GT;
    &LT; ListBoxItem的高度=50
                    CONTENT =Test3的/&GT;
    &LT; ListBoxItem的高度=50
                    CONTENT =TEST4/&GT;
    &LT; ListBoxItem的高度=50
                    CONTENT =TEST5/&GT;
    &LT; ListBoxItem的高度=50
                    CONTENT =TEST6/&GT;
    &LT; ListBoxItem的高度=50
                    CONTENT =TEST7/&GT;
    &LT; ListBoxItem的高度=50
                    CONTENT =Test8/&GT;
    &LT; ListBoxItem的高度=50
                    CONTENT =Test9/&GT;
    &LT; ListBoxItem的高度=50
                    CONTENT =Test10/&GT;&LT; /&的ListView GT;


  

在的ScrollViewer内容可以在物理单位来滚动
  或逻辑单元。物理单位与设备无关的像素。
  逻辑单元用于滚动一个ItemsControl中的项。该
  该ScrollViewer中的默认行为是用物理单位
  滚动的内容。然而,在情况下,CanContentScroll是
  设置为true,内容可以使用逻辑单元滚动。对于
  例如,列表框,的ListView,以及其他继承控制
  ItemsControl的使用逻辑单元滚动。如果CanContentScroll是真实的,
  该ExtentHeight的价值观,ScrollableHeight,ViewportHeight和
  VerticalOffset属性是项目的数量,而不是物理
  单位。


  
  

如果您需要物理滚动,而不是逻辑滚动,包
  在ScrollViewer中主机面板元素,并设置其CanContentScroll
  属性设置为false。物理滚动是默认的滚动行为
  对于大多数面板元件


I've got an app with multiple ListView controls where there's a requirement that the item's in the ListView must be fully visible. There should never be partial ListViewItem's showing in the list. If the user releases the ScrollViewer at a position that ends up showing a partial item, then the list should "snap" and correct itself so that only complete items are displayed.

Has anyone done this before? I think I'm going to need to overload ListView and/or ScrollViewer to do this. I'm looking for suggestions on how to approach this. Thanks.

Here is one of my lists:

<ctrls:SnapList x:Name="PART_ProductList" 
                                            ScrollViewer.CanContentScroll="False"  
                                            ScrollViewer.VerticalScrollBarVisibility="Auto" 
                                            ScrollViewer.HorizontalScrollBarVisibility="Hidden"
                                            ItemContainerStyle="{StaticResource ProductFinderItem}" 
                                            Canvas.Top="373" Canvas.Left="75"
                                            Height="910" Width="900" >

                            <ctrls:SnapList.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <VirtualizingStackPanel VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Standard" />
                                </ItemsPanelTemplate>
                            </ctrls:SnapList.ItemsPanel>

                            <ctrls:SnapList.Template>
                                    <ControlTemplate>
                                    <ScrollViewer  x:Name="Scroller" VerticalAlignment="Top"  CanContentScroll="True" Style="{StaticResource VertScrollViewer}" Focusable="false" >
                                                <ItemsPresenter   />
                                            </ScrollViewer>
                                    </ControlTemplate>
                            </ctrls:SnapList.Template>
                        </ctrls:SnapList>

解决方案

I believe you're looking for the ScrollViewer.CanContentScroll Property

If you know the maximum size of the item in the ListView, make sure that the ListView's Height is the same size, or a multiple of the item height.

Working Example:

<ListView ScrollViewer.CanContentScroll="True"
            Height="200">

    <ListBoxItem Height="50"
                    Content="Test1" />
    <ListBoxItem Height="50"
                    Content="Test2" />
    <ListBoxItem Height="50"
                    Content="Test3" />
    <ListBoxItem Height="50"
                    Content="Test4" />
    <ListBoxItem Height="50"
                    Content="Test5" />
    <ListBoxItem Height="50"
                    Content="Test6" />
    <ListBoxItem Height="50"
                    Content="Test7" />
    <ListBoxItem Height="50"
                    Content="Test8" />
    <ListBoxItem Height="50"
                    Content="Test9" />
    <ListBoxItem Height="50"
                    Content="Test10" />

</ListView>

Content in a ScrollViewer can be scrolled in terms of physical units or logical units. Physical units are device independent pixels. Logical units are used for scrolling items within an ItemsControl. The default behavior of the ScrollViewer is to use physical units to scroll its content. However, in cases where the CanContentScroll is set to true, the content could use logical units to scroll. For example, ListBox, ListView, and other controls that inherit from ItemsControl use logical units to scroll. If CanContentScroll is true, the values of the ExtentHeight, ScrollableHeight, ViewportHeight, and VerticalOffset properties are number of items, instead of physical units.

If you require physical scrolling instead of logical scrolling, wrap the host Panel element in a ScrollViewer and set its CanContentScroll property to false. Physical scrolling is the default scroll behavior for most Panel elements.

这篇关于WPF ListView中始终显示完整的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆