设为首页 加入收藏

TOP

背水一战 Windows 10 (58) - 控件(集合类): ListViewBase - ListView, GridView(一)
2017-10-13 10:42:01 】 浏览:4178
Tags:背水一战 Windows 控件 集合 ListViewBase ListView GridView

[源码下载]


背水一战 Windows 10 (58) - 控件(集合类): ListViewBase - ListView, GridView



作者:webabcd


介绍
背水一战 Windows 10 之 控件(集合类 - ListViewBase)

  • ListView
  • GridView



示例
1、ListView 的示例
Controls/CollectionControl/ListViewBaseDemo/ListViewDemo.xaml

<Page
    x:Class="Windows10.Controls.CollectionControl.ListViewDemo"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Windows10.Controls.CollectionControl"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"

    xmlns:common="using:Windows10.Common">

    <Page.Resources>
        <Style x:Key="ListViewItemStyle" TargetType="ListViewItem">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListViewItem">
                        <!--
                            ListViewItemPresenter - ListViewItem 的 Presenter(继承自 ContentPresenter, 请参见 /Controls/BaseControl/ContentControlDemo/ContentPresenterDemo.xaml)
                                有好多属性,详见文档
                                默认样式就是 generic.xaml 中的 <Style TargetType="ListViewItem"> 节点
                                如果需要自定义的话,那么就在 generic.xaml 中的 <Style TargetType="ListViewItem" x:Key="ListViewItemExpanded"> 节点的基础上修改
                                如果还不能满足要求的话就通过继承 ContentPresenter 来实现自定义的 ContentPresenter
                        -->
                        <!--
                            此处的 TemplatedParent 是 ListViewItem
                            这里借用 Tag 保存一下 ListViewItem 的 IsSelected,之后的数据模板可以绑定 ListViewItemPresenter 的 Tag,从而实现数据模板间接绑定 ListViewItem 的 IsSelected
                            此处通过 Tag 属性做中转,如果 Tag 有别的用处的话,那么就自己写个附加属性做中转吧
                        -->
                        <ListViewItemPresenter Margin="10" SelectedBackground="Red" SelectedPointerOverBackground="Red"
                                               Tag="{Binding IsSelected, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay}" />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <common:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
    </Page.Resources>

    <Grid Background="Transparent">

        <!--
            ListView - ListView 控件(继承自 ListViewBase, 请参见 /Controls/CollectionControl/ListViewBaseDemo/)
                ListView 的默认布局控件是 ItemsStackPanel,请参见 /Controls/CollectionControl/ItemsControlDemo/LayoutControl/ItemsStackPanelDemo.xaml
                ListView 的 ItemContainer 是 ListViewItem
        -->

        <ListView x:Name="listView" Margin="10 0 10 10" 
                  ItemContainerStyle="{StaticResource ListViewItemStyle}"
                  SelectionMode="Multiple"
                  ItemsSource="{x:Bind Employees}">
            <ListView.ItemTemplate>
                <DataTemplate x:DataType="common:Employee">
                    <StackPanel Height="100" Width="100" Background="Blue">
                        <TextBlock x:Name="lblName" Text="{x:Bind Name}" />
                        <TextBlock x:Name="lblIsMale" Text="{x:Bind IsMale}" />
                        <!--
                            这里有个需求:当 ListView
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇IOSerialize,xml和json,soap序列.. 下一篇分享一个我写的批量选择日期的方法

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目