'Unknown exception(just-in- time debugger exception) in ListView drag and drop in uwp?
The Below code is for reordering the items of listview using drag and drop functionality.
The Below code is almost similar to my actual project code except for the name property in the Entity class is of type RelativePanel, I am getting some unknown exception exactly at get;
in the name property while dropping the items at the different place it was before.
How to solve this unknown exception(just-in- time debugger exception).
In MainPage.xaml.
<Page.Resources>
<DataTemplate x:Key="dataTemplate" x:DataType="local:Entity">
<ContentPresenter Content="{Binding name}"></ContentPresenter>
</DataTemplate>
<Style TargetType="ListView" x:Key="ListViewStyle">
<Setter Property="AllowDrop" Value="True" />
<Setter Property="CanDragItems" Value="True" />
<Setter Property="CanReorderItems" Value="True" />
<Setter Property="SelectionMode" Value="Single" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden" />
<Setter Property="ScrollViewer.HorizontalScrollMode" Value="Enabled" />
<Setter Property="ScrollViewer.VerticalScrollMode" Value="Disabled" />
</Style>
</Page.Resources>
<Grid x:Name="xlgrid">
</Grid>
In MainPage.cs
namespace draganddrop1
{
public class Entity
{
public string name
{
get;
set;
}
public Entity(string name1)
{
name = name1;
}
}
public sealed partial class MainPage : Page
{
public ObservableCollection<Entity> Entities { get; set; }
ListView listView;
public MainPage()
{
this.InitializeComponent();
Entities = new ObservableCollection<Entity>();
populate();
var itemsPanelTemplateXaml =
$@"<ItemsPanelTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<ItemsStackPanel Orientation='Horizontal'/>
</ItemsPanelTemplate>";
this.
listView = new ListView { Style = (Style)this.Resources["ListViewStyle"], ItemTemplate = (DataTemplate)this.Resources["dataTemplate"] };
listView.ItemsPanel = (ItemsPanelTemplate)XamlReader.Load(itemsPanelTemplateXaml);
listView.ItemsSource = Entities;
xlgrid.Children.Add(listView);
}
private void populate()
{
for (int i = 0; i < 10; i++)
Entities.Add(new Entity("Sheet" + i.ToString()));
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|