我需要在使用 WinRT 创建的 Windows Phone 8.1 应用程序中创建可重新排序的 ListView。
XAML 如下(它绑定到代码隐藏中的 ObservableDictionary):
<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>
当我尝试对项目重新排序时,ListView 不执行任何操作(看起来“重新排序模式”未激活)。
当我在 Windows 8.1 中运行此示例(XAML 是共享的)时,它按预期工作。根据文档应支持 Windows Phone 8.1。
手机是否支持此功能(并且文档错误),还是我需要为手机做一些特殊的事情?
对于 WP 你需要设置ListViewBase.ReorderMode
这对我有用 - 不知道哪些属性是真正必要的; ReorderMode 在后面的代码中设置:
<ListView x:Name="fooListView"
ItemsSource="{Binding barlist, Mode=OneWay}"
SelectionMode="None"
AllowDrop="True" CanDragItems="True" IsSwipeEnabled="True" />
ListViewBase.Reorder 属性可用only对于 Windows Phone,因此如果您在通用应用程序的共享部分中有 XAML,则需要使用条件编译来设置它,如下所示:
#if WINDOWS_PHONE_APP
MainListView.ReorderMode = ListViewReorderMode.Enabled;
#endif
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)