locked
[UWP] ListView reorder not working RRS feed

  • Question

  • I have a ListView where I want to be able to reorder the items. With the code below, I can drag the items, but when I drop them in the list, the item jumps back to the previous location. What am I doing wrong?

    <ListView x:Name="lstvw" 
    	SelectionMode="None" 
    	CanDragItems="True"
    	AllowDrop="True" 
    	CanReorderItems="True" 
    	ReorderMode="Enabled" 
    	ItemTemplate="{StaticResource item}" 
    	RelativePanel.AlignHorizontalCenterWithPanel="True" 
    	Margin="0,90,0,0" Width="460" Height="810"/>
    Monday, December 21, 2015 9:16 AM

Answers

  • Hello,

    I wonder if you have bind the ListView ItemSource to a List, if so please try to bind your ListView ItemSource to a ObservableCollection instead of the List, for more information, please try to refer to the following message which comes from @Jerry Nixon's blog:
    ObservableCollection: the System.Collections.ObjectModel.ObservableCollection<T> is perhaps the handiest generic list available to XAML developers. Its CollectionChanged event is part of the XAML framework allowing developers to manipulate the collection’s membership from code-behind and trust the resulting UI properly reflects the change. Moreover, ObservableCollection is a required ItemsSource value to enable reordering.

    Best Regards,
    Amy Peng

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, December 22, 2015 3:15 AM

All replies

  • What is the ItemsSource filled with?
    Monday, December 21, 2015 10:36 AM
  • What is the ItemsSource filled with?

    <DataTemplate x:Name="item">
    	<Grid  Width="440" Height="100" Margin="7" Background="#FF003000">
    		<StackPanel Tag="{Binding ID}" Tapped="item_Tapped" VerticalAlignment="Center">
    			<TextBlock Text="{Binding Info}" Foreground="Lime" FontSize="18" Width="400" TextWrapping="Wrap" MaxLines="2" TextAlignment="Center"/>
    			<TextBlock Text="{Binding TypeString}" Foreground="Lime" FontSize="16" Width="400" TextAlignment="Center" Margin="0,10,0,0"/>
    		</StackPanel>
    	</Grid>
    </DataTemplate>
    

    But does it matter?
    Monday, December 21, 2015 10:50 AM
  • Hello,

    I wonder if you have bind the ListView ItemSource to a List, if so please try to bind your ListView ItemSource to a ObservableCollection instead of the List, for more information, please try to refer to the following message which comes from @Jerry Nixon's blog:
    ObservableCollection: the System.Collections.ObjectModel.ObservableCollection<T> is perhaps the handiest generic list available to XAML developers. Its CollectionChanged event is part of the XAML framework allowing developers to manipulate the collection’s membership from code-behind and trust the resulting UI properly reflects the change. Moreover, ObservableCollection is a required ItemsSource value to enable reordering.

    Best Regards,
    Amy Peng

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, December 22, 2015 3:15 AM