this is my xmal mainwindow :
<Window x:Class="HR1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel HorizontalAlignment="Left" Width="162">
<ListView ItemsSource="{Binding EventsCollection}" Background="AliceBlue" Height="311" >
<ListView.View>
<GridView>
<GridViewColumn Header="event Date" Width="112"/>
</GridView>
</ListView.View>
</ListView>
</StackPanel>
<ScrollViewer>
<StackPanel Margin="116,0,0,0" Width="284">
<ListView Name="employeeListView" ItemsSource="{Binding EmployeeCollection}">
<ListView.View>
<GridView>
<GridViewColumn Header="Employee ID" DisplayMemberBinding="{Binding Path=EmployeeID}" Width="80"/>
<GridViewColumn Header="First Name" DisplayMemberBinding="{Binding Path=FirstName}" Width="80"/>
<GridViewColumn Header="Last Name" DisplayMemberBinding="{Binding Path=LastName}" Width="80"/>
<!--<GridViewColumn Header="start" DisplayMemberBinding="{Binding Path=startHR}" Width="67" />
<GridViewColumn Header="finish" DisplayMemberBinding="{Binding Path=finishHR}" Width="67"/>-->
</GridView>
</ListView.View>
</ListView>
</StackPanel>
</ScrollViewer>
</Grid>
where this is the code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using HR1.Model;
namespace HR1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private CollectionView employeeCollection;
private CollectionView eventsCollection;
public MainWindow()
{
InitializeComponent();
initlalizeEmployeeList();
initlalizeEventDateList();
}
private void initlalizeEventDateList()
{
IList<employeeData> list = new List<employeeData>();
//query to database should be here
foreach (employeeData dataString in employeeDatesString)
{
list.Add(dataString );
}
employeeCollection = new CollectionView(list);
}
private void initlalizeEmployeeList()
{
IList<eventDate> list = new List<eventDate>();
//query to database should be here
foreach (eventDate dataString in eventDataString)
{
list.Add(dataString);
}
eventsCollection = new CollectionView(list);
}
#region collection binding setters
public CollectionView EmployeeCollection
{
get { return employeeCollection; }
}
public CollectionView EventsCollection
{
get { return eventsCollection; }
}
#endregion
#region myDatabinding
static employeeData []employeeDatesString = {new employeeData(1234,"yoav","stern "),new employeeData(1234,"yoav","stern ") };
static eventDate[] eventDataString = { new eventDate("111"), new eventDate("2222") };
#endregion
}
}
and this the data i store in tow classes which are stored in two places:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
namespace HR1.Model
{
class eventDate : INotifyPropertyChanged
{
public eventDate(string s)
{
Date = s;
}
#region private members
private string date;
#endregion
#region proprties
public string Date
{
get
{
return this.date;
}
set
{
date = value;
if (value != this.date)
{
this.date = value;
NotifyPropertyChanged("Date");
}
}
}
#endregion
#region events
public event PropertyChangedEventHandler PropertyChanged;
#endregion
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
}
and this the second one :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
namespace HR1.Model
{
class employeeData : INotifyPropertyChanged
{
public employeeData(long ID,string f,string l){
EmployeeID = ID;
LastName = l;
FirstName = f;
}
#region privete Members
private long employeeID;
private string firstName;
private string lastName;
#endregion
#region proprties
public long EmployeeID
{
get
{
return employeeID;
}
set
{
employeeID = value;
if (value != this.employeeID)
{
this.employeeID = value;
NotifyPropertyChanged("EmployeeID");
}
}
}
public string FirstName
{
get
{
return firstName;
}
set
{
firstName = value;
if (value != this.firstName)
{
this.firstName = value;
NotifyPropertyChanged("FirstName");
}
}
}
public string LastName
{
get
{
return lastName;
}
set
{
lastName = value;
if (value != this.lastName)
{
this.lastName = value;
NotifyPropertyChanged("LastName");
}
}
}
#endregion
#region events
public event PropertyChangedEventHandler PropertyChanged;
#endregion
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
}
notice : in my point of view somewhere where i declared EmployeeCollection and the xmal line:
<ListView Name="employeeListView" ItemsSource="{Binding EmployeeCollection}">
I did wrong couse the two doesn't bind as they should have