【发布时间】:2018-07-15 21:39:40
【问题描述】:
我正在制作一个 UWP 应用程序,它现在应该在 xbox 上,将来可能会在 pc 和其他平台上发布。我知道在 PC 和移动设备上,我们可以通过 GridView 或 ListView 上的以下 2 个属性启用此功能。
CanReorderItems=True
CanDrop=True
但根据 Microsoft Docs,拖放功能是 not available or supported on xbox。
那么还有哪些其他选项可以在 xbox GridView 上实现此重新排序功能?
更新 1
这是我的 gridview 后端代码。选择模式是单一的,但我没有使用 selectionchanged 事件,因为这只会造成很多混乱,现在只是假设我们总是需要交换项目,一旦交换工作完美,我将在稍后设置布尔值。
private void SamplePickerGridView_ChoosingItemContainer(Windows.UI.Xaml.Controls.ListViewBase sender, ChoosingItemContainerEventArgs args)
{
if (args.ItemContainer != null)
{
return;
}
GridViewItem container = (GridViewItem)args.ItemContainer ?? new GridViewItem();
//should be xbox actually after pc testing
if (DeviceTypeHelper.GetDeviceFormFactorType() == DeviceFormFactorType.Desktop)
{
container.GotFocus += Container_GotFocus;
container.LostFocus += Container_LostFocus;
//container.KeyDown += Container_KeyDown;
}
args.ItemContainer = container;
}
private TVShow GotItem, LostItem;
private void Container_LostFocus(object sender, RoutedEventArgs e)
{
LostItem = OnNowAllGridView.ItemFromContainer(e.OriginalSource as GridViewItem) as TVShow;
GotItem = null;
}
private void Container_GotFocus(object sender, RoutedEventArgs e)
{
GotItem = OnNowAllGridView.ItemFromContainer(e.OriginalSource as GridViewItem) as TVShow;
if (GotItem != null && LostItem != null)
{
var focusedItem = GotItem;
var lostitem = LostItem;
var index1 = ViewModel.Source.IndexOf(focusedItem);
var index2 = ViewModel.Source.IndexOf(lostitem);
ViewModel.Source.Move(index1, index2);
}
LostItem = null;
}
你可以尝试使用adaptivegridview的代码,或者只是普通的uwp gridview,如果它可以与adaptivegridview一起使用的话。
Current Bheaviour 项被交换,但焦点保持在同一索引处。
预期焦点也应该随着项目移动。
【问题讨论】:
标签: xaml gridview uwp xbox-one reorderlist