zoukankan      html  css  js  c++  java
  • [WPF疑难] 如何限定ListView列宽度

                                 [WPF疑难] 如何限定ListView列宽度
                                               周银辉

    今天遇到的一个Defect是:应该限定List View中列最小宽度以避免用户将列宽度拖拽为0而导致列消失。WPF的List View没有内置该机制,但我们可以通过监听用户拖拽操作来跟踪列宽并进一步限定用户拖拽,我已经搞定了该问题,请参见附件中的DEMO

    Demo中的“ListViewLayoutManagerLib”项目已经该操作封装,如何使用该封装,请参考下面的说明(或GridViewCodeDemo.Window1.xaml)

    1将ListViewLayoutManagerLib引入到项目中,名引入名字空间:xmlns:listViewMgr="clr-namespace:ListViewLayoutManagerLib;assembly=ListViewLayoutManagerLib"

    2在需要限定操作的ListView控件上启用ListViewManager:listViewMgr:ListViewLayoutManager.Enabled="True"

    3在需要限定的列上制定限定值  listViewMgr:RangeColumn.MinWidth="50"

                <ListView listViewMgr:ListViewLayoutManager.Enabled="True">

                <ListView.View >

                    <GridView AllowsColumnReorder="true">

                        <GridViewColumn

                            listViewMgr:RangeColumn.MinWidth="50"

                            Header="MinWidth100"

                            Width="150"/>

                        <GridViewColumn

                            listViewMgr:RangeColumn.MinWidth="100"

                            listViewMgr:RangeColumn.MaxWidth="200"

                            Header="Width100~200" Width="150"/>

                        <GridViewColumn Header="Normal" Width="150"/>

                    </GridView>

                </ListView.View>

            </ListView>

    Demo下载

  • 相关阅读:
    10.23 JSTL
    10.22 EL执行表达式
    10.21 EL表达式(只能在jsp中使用)
    10.20 网站访问量统计(application)
    10.19 JSP内置对象作用域
    10.16 Session和Cookie的区别
    10.15 转发与重定向
    剑指Offer_26_二叉搜索树与双向链表
    剑指Offer_25_复杂链表的复制
    剑指Offer_24_二叉树中和为某一值的路径.md
  • 原文地址:https://www.cnblogs.com/zhouyinhui/p/1213030.html
Copyright © 2011-2022 走看看