Note that there are some explanatory texts on larger screens.

plurals
  1. POListview displaying "empty" rows
    text
    copied!<p>I've spent a good couple of days failing at solving this issue myself, which leads me to believe I don't understand something very basic about xaml and the code-behind. I am attempting to display data from an ObservableCollection in a ListView using WPF and c#. </p> <p>When I start debugging, the window displays the listview, with the grid and the headers. There are clickable rows equivalent to the number of items that should be there, but the items appear blank or empty. I was working off an incomplete tutorial to try and learn my way through this, the code is as follows:</p> <p>MainWindow.xaml.cs:</p> <pre><code>public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } } </code></pre> <p>NameList.cs:</p> <pre><code>class NameList : ObservableCollection&lt;PersonName&gt; { public NameList() : base() { Add(new PersonName("Willa", "Cather")); //enumerated? (firstName, lastName) Add(new PersonName("Isak", "Dinesen")); Add(new PersonName("Victor", "Hugo")); Add(new PersonName("Jules", "Verne")); } } </code></pre> <p>PersonName.cs:</p> <pre><code>class PersonName { private string firstname; private string lastname; public PersonName(string first, string last) { this.firstname = first; this.lastname = last; } public string FirstName { get; set; } public string LastName { get; set; } } </code></pre> <p>I would include the xaml, but I haven't figured out how to do that in a question here, so I'll just spell it out as best I can:</p> <pre><code>ListView ItemsSource=""{Binding Source={StaticResource NameListData}}" GridViewColumn DisplayMemberBinding="{Binding Path=FirstName}" GridViewColumn DisplayMemberBinding="{Binding Path=LastName}" </code></pre> <p>I've only listed the actual bindings, I didn't think the layout info was too important, but let me know if I'm wrong in that assumption.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload