Update: I received an answer from MS via support channels that it is currently impossible to support touch reordering when the ItemPanelTemplate is a VariableSizeWrapGrid - because it lacks the implementation of some of the interfaces required for that.
As a foreword (and to eliminate any misunderstanding), I do have the required functionality working with the mouse. All I need is to achieve the same functionality with the touch gestures.
Requirements: 1. Display in a horizontally scrollable container a set of items, each of which may be of either half height or full height. It should be possible to rearrange them by dragging and dropping at a new position. 2. Give the user a way to deselect a previously selected item (to the same effect as right-clicking with the mouse does).
My current code:
XAML (slightly simplified for clarity)
<ScrollViewer HorizontalAlignment="Stretch"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Hidden">
<StackPanel Orientation="Horizontal" Height="600"
ScrollViewer.VerticalScrollMode="Disabled">
<controls:MyGridView ScrollViewer.VerticalScrollMode="Disabled"
ItemsSource="{Binding Items}"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
SelectionMode="Single"
IsSwipeEnabled="True"
CanDragItems="True"
CanReorderItems="True"
AllowDrop="True"
IsItemClickEnabled="False"
Height="600">
<GridView.ItemTemplate>
<DataTemplate>
<Grid>
<ContentControl Content="{Binding}"
ContentTemplateSelector="{StaticResource ItemTemplateSelector}"/>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<VariableSizedWrapGrid ItemHeight="300"
ItemWidth="300"
Orientation="Vertical"/>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<GridView.ItemContainerStyle>
<Style TargetType="GridViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
</Style>
</GridView.ItemContainerStyle>
</controls:DashletsGridView>
</StackPanel>
</ScrollViewer>
MyGridView class here is an extension of GridViewEx that is a part of this sample. The only addition it has to its base class is:
protected override void PrepareContainerForItemOverride(Windows.UI.Xaml.DependencyObject element, object item)
{
try
{
Item d = item as Item;
if (d != null)
{
element.SetValue(VariableSizedWrapGrid.RowSpanProperty, d.Size == PossibleSizes.Half ? 1 : 2);
}
}
catch
{
element.SetValue(VariableSizedWrapGrid.RowSpanProperty, 2);
}
finally
{
base.PrepareContainerForItemOverride(element, item);
}
}
I have tried a wide variety of layout control combinations (such as eliminating the outer ScrollViewer, or StackPanel, or replacing it with a grid), but none of those supported proper horizontal scrolling or item sizing. Switching the GridView.ItemsPanel from VariableSizedWrapGrid to just WrapGrid did not help either.
Please note the combination of flags: IsSwipeEnabled="True" CanDragItems="True" CanReorderItems="True" AllowDrop="True" IsItemClickEnabled="False". This is what's working with the mouse d&d, but still no luck with the touch d&d or deselection.