I am making my first Windows Store app in Visual Studios 2012. I have a gridview control that I have enabled to be reordered. I have code that I need to run when the list is reordered. I have tried the Drop event. It does not fire. I tried several other drag events, which also did not fire. It seems like this should be so simple... Thanks for your time!
相关问题
- WPF Binding from System.Windows.SystemParameters.P
- Xamarin. The name 'authorEntry does not exist
- XAML: Applying styles to nested controls
- How to properly change a resource dictionary
- Listview applies a check to other listview items h
相关文章
- WPF MVVMLight:在ViewModel中,开子线程为ObservableCollectio
- 关于ItemsControl的绑定问题
- XAML ComboBox SelectionChanged Fires OnLoad
- Windows 8.1 How to fix this obsolete code?
- Show flyout using BottomAppBar
- Why does my ScrollViewer destroy my Grid Layout? W
- Can I add/subtract value that is bound to an eleme
- How to overlay items in StackPanel or ListView?
You cannot reorder a
GridView
unless theItemsSource
is bound to anObservableCollection
andCanReorderItems
,CanDragItems
, andAllowDrop
are set totrue
. It is not necessary to use aCollectionViewSource
to enable reordering in yourgridview
. In fact, acollectionviewsource
is often used for grouping agridview
and reordering is not possible when data is grouped.Anyway, your XAML would look like this:
Although any
enumerable
can be bound to theItemsSource
of aGridView
it is only anObservableCollection
that enables reorder. Yes, you can use a custom type that implements reorder, but why mess with that whenObservableCollection
does it for you?Your view model might look like this:
In the code above, the reorder
event
is not real. It is derived from a combination of the "Remove" action and the "Add" action in theCollectionChanged
event. Here's why this is awesome. If the reorder was only available from theGridView
then theViewModel
would not be able to handle it. Because the underlying list is how you detect reorder, theViewModel
is enabled.Every case is slightly different. You may not care about the Index so you can simplify the code. You may not allow adding or removing from the collection so you only need to monitor the Add action. Again, it depends on your situation. My sample code above should get 99% of the cases taken care of.
Remember,
GridView
is not the only control that allows reorder. Any control based onListViewBase
(like theListView
) supports reorder - still usingObservableCollection
. ButGridView
is the most common control to use this feature. For sure.Oh, to answer your question!
There is no event that indicates a reorder. Reorder is a derived action based on a combination of actions in the underlying
ObservableCollection
CollectionChanged
event. Make sense?By the way, here's sample syntax to bind to a
CollectionViewSource
, if you choose to:Best of luck.