Hello,
I am a new programmer and decided to try some C# code in WPF using MVVM. What I want to do is simple, I think, but I am having some issues wrapping my head around binding to the GridView. What I want to do is create a hardcoded list (for starters)of people--for example employees. I want the list to be displayed in a grid with the following column headings firstName, lastName, and department.
In the spirit of MVVM I have three classes: the Model, ViewModel, and View. I have searched long and hard for solutions that are similar, and followed many to every detail, but my data is not showing up. Perhaps, if one of you more experienced can take a look, you can point out where I am going wrong.
MY VIEW
<window x:class="WpfApplication3.MainWindow" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication3"
Title="MainWindow" Height="350" Width="525" IsEnabled="True">
<listview itemssource="{Binding EmployeeData}">
<listview.view>
<gridview>
<gridviewcolumn width="140" header="First Name">
DisplayMemberBinding="{Binding Path=firstName}"/>
<gridviewcolumn width="140" header="Last Name">
DisplayMemberBinding="{Binding lastName}" />
<gridviewcolumn width="140" header="Department">
DisplayMemberBinding="{Binding department}" />
</gridviewcolumn></gridviewcolumn></gridviewcolumn></gridview>
</listview.view>
</listview>
</window>
MY VIEWMODEL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WpfApplication3.Model;
using System.Collections.ObjectModel;
namespace WpfApplication3.ViewModel
{
public class EmployeeListing
{
List<employee> _EmployeeData = new List<employee>();
public EmployeeListing()
{
_EmployeeData.Add(new Employee()
{
firstName = "Jackie",
lastName = "O",
department = "IT"
});
_EmployeeData.Add(new Employee()
{
firstName = "Billy",
lastName = "Bob",
department = "Finance"
});
}
}
}</employee></employee>
MY MODEL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WpfApplication3.Model
{
public class Employee
{
public string firstName { get; set; }
public string lastName { get; set; }
public string department { get; set; }
}
}