问题描述
Hey Guys,
我' m试图允许用户重新排序gridview中的项目。这可以在UI中工作,但我正在尝试捕获drop事件,以便我可以将订单保存回数据库,但是我不确定要捕获哪个事件。当我操作GridView中的项目时,我附加
以下的事件都没有被触发。
I'm trying to allow the user to reorder items in a gridview. This works in the UI but I am trying to capture the drop event so that I can save the order back to the database, however I'm unsure what event to capture. None of the events I have attached to below get fired when I manipulate the items in the GridView.
<GridView x:Name="gvQuestions" Grid.Row="1" ItemsSource="{Binding Questions,Mode=TwoWay}" CanDragItems="True" AllowDrop="True" CanReorderItems="True" ManipulationStarted="gvQuestions_ManipulationStarted_1" ManipulationCompleted="gvQuestions_ManipulationCompleted_1" Foreground="White" DragEnter="GridView_DragEnter_1" DragLeave="GridView_DragLeave_1" Drop="ReorderItem_done" PointerReleased="released" >
<GridView.ItemTemplate>
<DataTemplate>
<StackPanel Drop="StackPanel_Drop_1" Height="115" Orientation="Horizontal" Margin="10" VerticalAlignment="Stretch" HorizontalAlignment="Left" >
<TextBlock Style="{StaticResource BasicTextStyle}" TextWrapping="Wrap" Width="200" VerticalAlignment="Center" Margin="5" Text="{Binding QuestionText}" HorizontalAlignment="Left" />
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
根据这篇文章所有我应该做的事情是 附加到 DragEnter event,
DragLeave 事件和功能的事件。
According to this article all I should need to do is attach to the DragEnter event,DragLeave event, and Drop event.
http://social.msdn.microsoft.com/Forums/en-AU/winappswithcsharp/thread/f401f4a8-9c56-45ff-9aa6-7b06768143c5
但如上所述,没有一个事件得到被解雇。我甚至在父< Grid>上附加了 包含gridview的文件,以及上面的FlipViewItem,以及上面的FlipView。他们都没有被解雇。
But as said, none of the events get fired. I even attached to the drop event on the parent <Grid> on which the gridview is contained and on the FlipViewItem above that, and the FlipView above that. None of them get fired.
推荐答案
您可以订阅ListView.DragItemsStarting事件,您可以在其中设置拖动数据。
You can subscribe ListView.DragItemsStarting event where you can set the drag data.
尝试一下:
<StackPanel> <ListView x:Name="listViewDataItems" CanDragItems="True" DragItemsStarting="listViewDataItems_DragItemsStarting_1" SelectionMode="Multiple" ItemsSource="{Binding}"> <ListView.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Path=Text}"/> </DataTemplate> </ListView.ItemTemplate> </ListView> <Border AllowDrop="True" Drop="Border_Drop_1" Background="Green"> <TextBlock Name="tb" Height="100"/> </Border>
protected override void OnNavigatedTo(NavigationEventArgs e) { listViewDataItems.DataContext = new ObservableCollection<MItem> { new MItem(){Text="A"}, new MItem(){Text="B"}, new MItem(){Text="C"}, new MItem(){Text="D"} }; } class MItem { public string Text { get; set; } } private async void Border_Drop_1(object sender, DragEventArgs e) { tb.Text = await e.Data.GetView().GetTextAsync(); } private void listViewDataItems_DragItemsStarting_1(object sender, DragItemsStartingEventArgs e) { e.Data.SetText(((MItem)e.Items[0]).Text);
我希望这个帮助,
詹姆斯
这篇关于GridView Drop事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!