WinRT 8.1 Phone - ListView reordering

ε祈祈猫儿з 提交于 2019-12-19 08:26:45

问题


I need to create a reorderable ListView in a Windows Phone 8.1 app created using WinRT. The XAML is the following (it binds to an ObservableDictionary in the codebehind):

<Grid Margin="24">
        <ListView x:Name="MainListView" CanDragItems="True" CanReorderItems="True" AllowDrop="True" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Border Padding="24" Margin="16" Background="CadetBlue">
                        <TextBlock Text="{Binding}" />
                    </Border>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>

The ListView does nothing when I try to reorder the items (it looks like the "reordering mode" is not activated).

When I run this sample in Windows 8.1 (the XAML is shared) it works as expected. According to the documentation Windows Phone 8.1 should be supported.

Is this functionality supported on the phone (and the documentation wrong) or do I need to do something special for the phone?


回答1:


For WP you need to set ListViewBase.ReorderMode

This is what works for me - no idea which properties are really necessary; ReorderMode is set in code behind:

<ListView x:Name="fooListView"
          ItemsSource="{Binding barlist, Mode=OneWay}" 
          SelectionMode="None"                
          AllowDrop="True" CanDragItems="True" IsSwipeEnabled="True" />

The ListViewBase.Reorder property is available only for Windows Phone, so if you have the XAML in a Shared part of a universal app, you need to set it using conditional compile like so:

#if WINDOWS_PHONE_APP
            MainListView.ReorderMode =  ListViewReorderMode.Enabled;
#endif



回答2:


It appears that the property CanReorderItems is not supported on Windows Phone 8.1.

(I tried a simple example, and it does not work, and I could not find any combination that made it work as it does on Windows 8.1.)



来源:https://stackoverflow.com/questions/23875849/winrt-8-1-phone-listview-reordering

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!