User avatar
polycular
Topic Author
Posts: 19
Joined: 29 Sep 2015, 18:18

[Unity] Crashes when using <ListView>

31 May 2016, 15:53

Hi,

the usage of a <ListView> within our xaml files results in a NoesisGUI exception / an Unity3D crash. I created a new project which only contains Noesis and one xaml file.

Unity x86 5.3.5 p1 | Windows 8.1 pro x64 -> crash exception (dump files attached)
Unity 5.3.4 f1 | Mac 10.11.4 -> UnityEditor crashes
Noesis 1.2.6 f2 / f3


XAML:
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

	 <Rectangle Fill="orange" Height="100" Width="100" />
	 <Rectangle Fill="green" Height="50" Width="50" />

</Grid>
works fine but:
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

	 <Rectangle Fill="orange" Height="100" Width="100" />
	 <Rectangle Fill="green" Height="50" Width="50" />

	 <ListView />

</Grid>
results in the described behaviour. I also tried a non-empty ListView but it still leads to the same result.

Is there anything to keep in mind when working with <ListView>?


Best regards,
Michael
 
User avatar
sfernandez
Site Admin
Posts: 3184
Joined: 22 Dec 2011, 19:20

Re: [Unity] Crashes when using <ListView>

31 May 2016, 20:37

Hi,

I was able to reproduce the crash. It happens when you don't provide a View for the ListView.
You should provide one until we fix this bug:
<ListView ...>
  <ListView.View>
    <GridView>
      <GridViewColumn .../>
      ...
    </GridView>
  </ListView.View>
</ListView>
 
User avatar
polycular
Topic Author
Posts: 19
Joined: 29 Sep 2015, 18:18

Re: [Unity] Crashes when using <ListView>

07 Jun 2016, 15:27

Thx for your help! I'm meanwhile using an ItemsControl which works perfectly fine :)
 
User avatar
polycular
Topic Author
Posts: 19
Joined: 29 Sep 2015, 18:18

Re: [Unity] Crashes when using <ListView>

29 Jun 2016, 14:40

Hi,

we reached a point where we need to use a ListView to display data instead of an ItemsControl. Unfortunately the ListView control doesn't work at the moment when no View is provided (no entries). As a result of the design / layout a GridView isn't an option.

We are using Noesis 1.2.6f4.

This is the code I used for testing:

CS:
using System.Collections.Generic;

using Noesis;
using UnityEngine;


public class User
{
	public string Name { get; set; }
	public int Age { get; set; }
}

public class ListViewDemo : MonoBehaviour
{
	Grid root;
	ListView lv;

	void Start()
	{
		List<User> items = new List<User>();
		items.Add(new User() { Name = "John Doe", Age = 42 });
		items.Add(new User() { Name = "Jane Doe", Age = 39 });
		items.Add(new User() { Name = "Sammy Doe", Age = 13 });

		NoesisGUIPanel noesis = FindObjectOfType<NoesisGUIPanel>();
		root = noesis.GetContent() as Grid;

		if (root == null)
			return;

		lv = root.FindName("lvData") as ListView;

		if (lv == null)
			return;

		lv.ItemsSource = items;
	}
}
XAML:
<Grid
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>

	<ListView x:Name="lvData">
		<ListView.View>
			<GridView>
				<GridViewColumn Header="Name" Width="120" DisplayMemberBinding="{Binding Name}" />
			</GridView>
		</ListView.View>

		<ListView.ItemTemplate>
			<DataTemplate>
				<WrapPanel>
					<TextBlock Text="Name: " />
					<TextBlock Text="{Binding Name}" />
					<TextBlock Text=", " />
					<TextBlock Text="Age: " />
					<TextBlock Text="{Binding Age}" />
				</WrapPanel>
			</DataTemplate>
		</ListView.ItemTemplate>
	</ListView>

</Grid>
If the <ListView.View> ... </ListView.View> entry is removed the ListView isn't populated anymore.


Is this problem something that can be fixed in the near future? Or will the fix be part of a later release? / Is there any valid workaround?
 
User avatar
sfernandez
Site Admin
Posts: 3184
Joined: 22 Dec 2011, 19:20

Re: [Unity] Crashes when using <ListView>

30 Jun 2016, 21:03

Hi,

Right now the ListView requires a View (a GridView in particular) to specify the columns. This GridView describes how many columns are going to be shown for each item, and what property will be bound in the column.

Without a View the ListView doesn't have much sense, and maybe a ListBox is a better option.

If you want to simulate a ListBox using a ListView, you can define just one column, and bind the whole item. This is what we will do in the future when no View is specified:
<ListView ItemsSource="{Binding Users}">
  <ListView.View>
    <GridView>
      <GridViewColumn Header="" DisplayMemberBinding="{Binding}" />
    </GridView>
  </ListView.View>
</ListView>

Who is online

Users browsing this forum: Ahrefs [Bot], dstewart, JackM and 6 guests