[英]Can't drag items from a ListView in my Windows Phone 8.1 app
I am creating my very first Windows Phone 8.1 app as part of a Windows Store Universal app. 我正在创建我的第一个Windows Phone 8.1应用程序作为Windows Store Universal应用程序的一部分。 The Desktop/tablet version is done and has been in the store for a few weeks, and it works great.
桌面/平板电脑版本已经完成,已在商店中存放了几周,而且效果很好。 I'm being careful and assuming as little as possible as I build out the Phone version, and I have had reasonable success so far.
我小心翼翼地假设尽可能少地构建电话版本,到目前为止我已经取得了合理的成功。 However, there is one problem that I just haven't been able to sort out through experimentation, Stackoverflow or Google: I can't get items in a ListView to be draggable.
但是,有一个问题我无法通过实验,Stackoverflow或Google来解决:我无法让ListView中的项目可以拖动。
Here's a shot of one of the pages from my app: 这是我的应用程序中的一个页面的镜头:
The user creates a workout routine by dragging exercises from the ListView on the right-hand side to the area on the left-hand side. 用户通过将练习从右侧的ListView拖动到左侧的区域来创建锻炼程序。 They can drag an exercise as many times as they want;
他们可以随意拖动练习次数; that's why it's not just a single list on which items can be checked.
这就是为什么它不仅仅是一个可以检查项目的列表。
This works perfectly on the desktop/tablet version, but on the phone version, when I click and hold an item, I can't drag it anywhere. 这适用于桌面/平板电脑版本,但在手机版本上,当我点击并按住某个项目时,我无法将其拖动到任何位置。 It won't move, and it doesn't show any affordance to indicate that it is draggable.
它不会移动,也没有显示任何可以表明它是可拖动的。
Here is the XAML that I use to define the ListView. 这是我用来定义ListView的XAML。 It is nearly identical to the working version, but I have turned on some properties that aren't present there (
IsSwipeEnabled
I think), hoping that they would make the magic work: 它与工作版本几乎完全相同,但是我已经打开了一些不存在的属性(我认为是
IsSwipeEnabled
),希望它们能够完成神奇的工作:
<ListView x:Name="StepsList" ItemsSource="{Binding Steps}"
ContainerContentChanging="ItemView_ContainerContentChanging"
SelectionMode="Single" Drop="StepsList_Drop"
Tapped="StepsList_Tapped"
CanDragItems="True"
AllowDrop="True"
ScrollViewer.VerticalScrollBarVisibility="Auto"
Grid.Row="1" Grid.Column="1"
DragItemsStarting="StepsList_DragItemsStarting"
Margin="5,0"
IsSwipeEnabled="True"
SelectionChanged="StepsList_SelectionChanged">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="MinWidth" Value="300" />
<Setter Property="MaxWidth" Value="300" />
<Setter Property="AllowDrop" Value="True" />
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<local:StepControl Role="StepsSource" Tapped="StepSourceItem_Tapped" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I put a break point inside the DragItemsStarting
event handler code, and it is never hit. 我在
DragItemsStarting
事件处理程序代码中放置了一个断点,它永远不会被命中。
你需要在后面的代码中设置它。
StepsList.ReorderMode = ListViewReorderMode.Enabled;
The MSDN documentation for dragging shows that only the Windows 8.1 app will support it unfortunately. 用于拖动的MSDN文档显示,不幸的是,只有Windows 8.1应用程序才支持它。
Edit: Having delved deeper, it seems it should be supported through Universal app development across both platforms. 编辑:深入研究后,似乎应该通过跨平台的通用应用程序开发来支持它。 Does the dragging functionality work in your Windows 8.1 app?
拖动功能是否适用于Windows 8.1应用程序?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.