背水一战 Windows 10 (56) - 控件(集合类): ListViewBase - 基础知识, 拖动项
2021-05-12 19:27
标签:combobox ppi async xaml order footer result ini rgs [源码下载] 作者:webabcd 示例 Controls/CollectionControl/ListViewBaseDemo/ListViewBaseDemo1.xaml.cs Controls/CollectionControl/ListViewBaseDemo/ListViewBaseDemo2.xaml.cs OK 背水一战 Windows 10 (56) - 控件(集合类): ListViewBase - 基础知识, 拖动项 标签:combobox ppi async xaml order footer result ini rgs 原文地址:http://www.cnblogs.com/lonelyxmas/p/7568311.html
介绍
背水一战 Windows 10 之 控件(集合类 - ListViewBase)
1、ListViewBase 的基础知识
Controls/CollectionControl/ListViewBaseDemo/ListViewBaseDemo1.xamlPage
x:Class="Windows10.Controls.CollectionControl.ListViewBaseDemo.ListViewBaseDemo1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Controls.CollectionControl.ListViewBaseDemo"
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">
Grid Background="Transparent">
Grid Margin="10 0 10 10">
StackPanel Orientation="Vertical">
TextBlock Name="lblMsg1" />
TextBlock Name="lblMsg2" Margin="0 10 0 0" />
StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="0 10 0 0">
CheckBox Name="chkIsItemClickEnabled" Content="IsItemClickEnabled" Margin="10 0 0 0" />
CheckBox Name="chkShowsScrollingPlaceholders" Content="ShowsScrollingPlaceholders" Margin="10 0 0 0" />
CheckBox Name="chkIsMultiSelectCheckBoxEnabled" Content="IsMultiSelectCheckBoxEnabled" Margin="10 0 0 0" />
ComboBox Name="cmbSelectionMode" PlaceholderText="SelectionMode" SelectionChanged="cmbSelectionMode_SelectionChanged" Margin="10 0 0 0">
ComboBoxItem>NoneComboBoxItem>
ComboBoxItem>SingleComboBoxItem>
ComboBoxItem>MultipleComboBoxItem>
ComboBoxItem>ExtendedComboBoxItem>
ComboBox>
StackPanel>
StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="0 10 0 0">
Button Name="buttonScrollDefault" Content="滚动到第 101 条数据 ScrollIntoViewAlignment.Default" Click="buttonScrollDefault_Click" />
Button Name="buttonScrollLeading" Content="滚动到第 101 条数据 ScrollIntoViewAlignment.Leading" Click="buttonScrollLeading_Click" Margin="10 0 0 0" />
Button Name="buttonSelect" Content="选中第 3 到第 6 项" Click="buttonSelect_Click" Margin="10 0 0 0" />
StackPanel>
StackPanel>
ListView x:Name="listView" VerticalAlignment="Top" HorizontalAlignment="Left" ItemsSource="{x:Bind Data}" Margin="0 150 10 10"
ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto"
SelectionMode="Single"
IsItemClickEnabled="{Binding IsChecked, ElementName=chkIsItemClickEnabled}"
ShowsScrollingPlaceholders ="{Binding IsChecked, ElementName=chkShowsScrollingPlaceholders}"
IsMultiSelectCheckBoxEnabled="{Binding IsChecked, ElementName=chkIsMultiSelectCheckBoxEnabled}"
SelectionChanged="listView_SelectionChanged"
ItemClick="listView_ItemClick">
ListView.ItemTemplate>
DataTemplate x:DataType="common:Employee">
StackPanel Orientation="Horizontal">
TextBlock Text="{x:Bind Name, Mode=TwoWay}" />
TextBlock Text="{x:Bind Age, Mode=TwoWay}" Margin="10 0 0 0" />
StackPanel>
DataTemplate>
ListView.ItemTemplate>
ListView.HeaderTemplate>
DataTemplate>
TextBlock Text="header" />
DataTemplate>
ListView.HeaderTemplate>
ListView.HeaderTransitions>
TransitionCollection>
EntranceThemeTransition FromHorizontalOffset="100" />
TransitionCollection>
ListView.HeaderTransitions>
ListView.FooterTemplate>
DataTemplate>
TextBlock Text="footer" />
DataTemplate>
ListView.FooterTemplate>
ListView.FooterTransitions>
TransitionCollection>
EntranceThemeTransition />
TransitionCollection>
ListView.FooterTransitions>
ListView>
Grid>
Grid>
Page>
/*
* ListViewBase(基类) - 列表控件基类(继承自 Selector, 请参见 /Controls/SelectionControl/SelectorDemo.xaml)
* SelectedItems - 被选中的 items 集合(只读)
* SelectedRanges - 被选中的 items 的范围(只读)
* SelectAll() - 选中全部 items
* SelectRange(ItemIndexRange itemIndexRange) - 选中指定范围的 items
* DeselectRange(ItemIndexRange itemIndexRange) - 取消选中指定范围的 items
* ScrollIntoView(object item, ScrollIntoViewAlignment alignment) - 滚动到指定的 item
* ScrollIntoViewAlignment.Default - 不好解释,请自己看演示效果
* ScrollIntoViewAlignment.Leading - 不好解释,请自己看演示效果
*
* ItemIndexRange - items 的范围
* FirstIndex - 范围的第一个 item 的索引位置
* LastIndex - 范围的最后一个 item 的索引位置
* Length - 范围的长度
*
*
* 注:
* ListViewBase 实现了 ISemanticZoomInformation 接口,所以可以在 SemanticZoom 的两个视图间有关联地切换。关于 ISemanticZoomInformation 请参见 /Controls/CollectionControl/SemanticZoomDemo/ISemanticZoomInformationDemo.xaml
*
*
* 本例用于演示 ListViewBase 的基础知识
*/
using System;
using System.Collections.ObjectModel;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
using System.Linq;
using Windows10.Common;
using Windows.UI.Xaml;
using Windows.UI.Popups;
namespace Windows10.Controls.CollectionControl.ListViewBaseDemo
{
public sealed partial class ListViewBaseDemo1 : Page
{
public ObservableCollection
2、ListViewBase 内拖动 item
Controls/CollectionControl/ListViewBaseDemo/ListViewBaseDemo2.xamlPage
x:Class="Windows10.Controls.CollectionControl.ListViewBaseDemo.ListViewBaseDemo2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Controls.CollectionControl.ListViewBaseDemo"
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>
DataTemplate x:Key="ItemTemplate" x:DataType="common:Employee">
StackPanel Background="Orange" Width="100">
TextBlock TextWrapping="Wrap" Text="{x:Bind Name}" HorizontalAlignment="Left" />
TextBlock TextWrapping="Wrap" Text="{x:Bind Age}" HorizontalAlignment="Left"/>
StackPanel>
DataTemplate>
Page.Resources>
Grid Background="Transparent">
StackPanel Margin="10 0 10 10">
Button Name="buttonMove" Content="通过 api 将 gridView1 中的第 1 项数据移动到第 3 项数据的位置" Click="buttonMove_Click" Margin="0 0 0 10" />
GridView Name="gridView1" Margin="5" VerticalAlignment="Top" Height="100" ItemsSource="{x:Bind Data1}" Background="White"
ItemTemplate="{StaticResource ItemTemplate}"
CanDragItems="True" CanReorderItems="True" AllowDrop="True"
DragItemsStarting="gridView_DragItemsStarting"
DragItemsCompleted="gridView_DragItemsCompleted" />
GridView Name="gridView2" Margin="5" VerticalAlignment="Top" Height="100" ItemsSource="{x:Bind Data2}" Background="White"
ItemTemplate="{StaticResource ItemTemplate}"
CanDragItems="True" CanReorderItems="True" AllowDrop="True"
DragItemsStarting="gridView_DragItemsStarting"
DragItemsCompleted="gridView_DragItemsCompleted"
DragEnter="gridView2_DragEnter"
Drop="gridView2_Drop"/>
TextBlock Name="lblEmployee" Margin="5" Foreground="Orange" Text="{x:Bind Path=Employee.Name}"
PointerPressed="lblEmployee_PointerPressed" DragStarting="lblEmployee_DragStarting" />
Border Name="borderDelete" Margin="5" Width="300" Height="100" BorderThickness="1" BorderBrush="Red" Background="Blue"
AllowDrop="True" Drop="borderDelete_Drop" DragEnter="borderDelete_DragEnter" DragLeave="borderDelete_DragLeave" DragOver="borderDelete_DragOver">
TextBlock FontSize="32" Text="拖动到此处以删除" TextAlignment="Center" VerticalAlignment="Center" />
Border>
TextBlock Name="lblMsg" Margin="5" Text="通过拖动 GirdView 中的 Item 进行排序" />
StackPanel>
Grid>
Page>
/*
* ListViewBase(基类) - 列表控件基类(继承自 Selector, 请参见 /Controls/SelectionControl/SelectorDemo.xaml)
*
*
* DragItemsStartingEventArgs
* Items - 被拖动的 items 集合
* Cancel - 是否取消拖动操作
* Data - 一个 DataPackage 类型的对象,用于传递数据
*
* DragItemsCompletedEventArgs
* DropResult - drop 的结果(None, Copy, Move, Link)
* Items - 被拖动的 items 集合
*
*
* 注:
* 1、drag-drop 传递数据,剪切板传递数据,分享传递数据,以及其他场景的数据传递均通过 DataPackage 类型的对象来完成
* 2、本例通过一个私有字段传递数据,通过 DataPackage 传递数据请参见:/Controls/BaseControl/UIElementDemo/DragDropDemo.xaml
* 3、关于 UIElement 拖放的详细说明请参见:/Controls/BaseControl/UIElementDemo/DragDropDemo.xaml
*
*
* 本例用于演示如何在 ListViewBase 内拖动 item 以对 item 排序,以及如何拖动 item 到 ListViewBase 外的指定位置以删除 item,以及如何拖动一个 UIElement 到 ListViewBase 内以添加这个 item
*/
using System.Collections.ObjectModel;
using Windows.UI.Xaml.Controls;
using System.Linq;
using Windows.UI.Xaml;
using System.Diagnostics;
using Windows10.Common;
using Windows.ApplicationModel.DataTransfer;
using System.Collections.Specialized;
using System;
using Windows.UI.Xaml.Input;
namespace Windows10.Controls.CollectionControl.ListViewBaseDemo
{
public sealed partial class ListViewBaseDemo2 : Page
{
// gridView1 的数据源
public ObservableCollection
[源码下载]
文章标题:背水一战 Windows 10 (56) - 控件(集合类): ListViewBase - 基础知识, 拖动项
文章链接:http://soscw.com/index.php/essay/84817.html