[英]Unable to reorder items in GridView when WrapPanel is used UWP
並且正在創建一個排序應用程序,在某些情況下,我將隱藏gridview項,並且遇到與此人相同的錯誤:
隱藏GridViewItem並在GridView中重新放置項目
因此我實現了該修復程序並且可以正常工作,但是突然就不允許在GridView中拖動和重新排序項目了。據我所知,它僅在將WrapPanel實現到gridView.ItemsPanel
並刪除后才出現重新排序。
這是我的XML代碼:
<Page
x:Class="ImageSorting.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ImageSorting"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:data ="using:ImageSorting.Models"
xmlns:toolkit="using:WinRTXamlToolkit.Controls"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid HorizontalAlignment="Stretch" Height="57" VerticalAlignment="Top">
<Border BorderBrush="Black" BorderThickness="0 0 0 1" HorizontalAlignment="Stretch" Height="57" VerticalAlignment="Top"/>
<Button x:Name="SelectFolder" Content="Select Folder" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,11,10,0" Background="#80a4ec" Click="SelectFolder_Click"/>
<Button x:Name="AddFolder" Content="Add Folder" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,11,125,0" Background="#84eeb1" Click="AddFolder_Click" />
<Button x:Name="Save" Content="Save" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,11,230,0" Background="#ece880" Click="Save_Click"/>
<ComboBox x:Name="ImageFolder" HorizontalAlignment="Left" VerticalAlignment="Top" Margin=" 20 11 0 0" SelectedIndex="0" SelectionChanged="ImageFolder_SelectionChanged">
<ComboBoxItem>All Images</ComboBoxItem>
</ComboBox>
</Grid>
<GridView x:Name="ImageGrid" HorizontalAlignment="Stretch" Margin="10,60,10,0" VerticalAlignment="Stretch" ItemsSource="{x:Bind ImgList, Mode=OneWay}" CanDragItems="True" AllowDrop="True" CanReorderItems="True" SelectionMode="Extended">
<GridView.ItemTemplate>
<DataTemplate x:DataType="data:Images">
<StackPanel>
<Image x:Name="Image" Width="206" Height="158" Source="{x:Bind imageData}" DoubleTapped="Image_DoubleTapped"/>
<StackPanel Orientation="Horizontal">
<TextBlock HorizontalAlignment="Left" FontSize="15" Text="{x:Bind imageNumber}" Margin="10 5 0 0"/>
<TextBlock HorizontalAlignment="Left" TextAlignment="Left" Width="100" FontSize="15" Text="{x:Bind altChar}" Margin="10 5 0 0"/>
<CheckBox x:Name="altNumber" HorizontalAlignment="Right" MinWidth="0" Margin="35 0 0 0" Click="altNumber_Click"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel Orientation="Horizontal" AllowDrop="True">
</toolkit:WrapPanel>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
</GridView>
<Grid x:Name="ConfirmGrid" HorizontalAlignment="Stretch" Height="50" VerticalAlignment="Bottom" Background="White" Visibility="Collapsed">
<Border BorderBrush="Black" BorderThickness="0 1 0 0" HorizontalAlignment="Stretch" Height="57" VerticalAlignment="Top" />
<Button x:Name="FolderConfirm" Content="Confirm" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,10,10,0" RenderTransformOrigin="-0.128,7.104" Click="FolderConfirm_Click" />
</Grid>
</Grid>
當我嘗試使用WrapPanel拖動GridView的項並對其重新排序時的圖像:
我是否缺少WinRTXamlToolkit中說明的內容,或者沒有解決此問題的方法。
更新2017年11月27日
因此,在按照@ Xavier Xie-MSFT的建議進行了一些修改之后,請嘗試繼承WrapPanel
類並從那里嘗試,從而實現WinRT工具箱的拖放重新排序功能。 這是我到目前為止發現的,
WrapPanel
繼承了Panel
類 WrapPanel
也繼承了Panel,因此,我想到所有動態包裝都需要繼承Panel
類。 Panel
類沒有任何用於檢測項目拖動事件的代碼(要么就是我拖動了錯誤的東西) ItemsWrapPanel
是一個密封類,它使我無法繼承,也適用於它繼承的任何接口 這是我到目前為止所發現的結論,如果發現任何問題,它將繼續更新。
感謝@ Xavier Xie-MSFT指出了正確的方向。
WinRTXamlToolkit的WrapPanel尚未實現重新排序功能。 您將需要手動執行重新排序,並監聽拖放事件。
如果您想自己實現,則可以閱讀Jerry Nixon的博客演練:使用拖放功能對GridView中的項目進行重新排序,以了解GridView重新排序的基本原理。
作為一種簡單的解決方法,可以將ItemsStackPanel
控件用作ItemsStackPanel
,它已實現了重新排序功能。 隱藏一個項目時,此控件也將沒有空格。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.