i am doing this xaml :
<StackPanel Margin="320,0,0,0" Grid.RowSpan="2">
<ListView ItemsSource="{Binding employeeCollection}">
<ListView.View>
<GridView>
<GridViewColumn Header="Employee ID" DisplayMemberBinding="{Binding Path=EmployeeID}"/>
<GridViewColumn Header="First Name" DisplayMemberBinding="{Binding Path=FirstName}"/>
<GridViewColumn Header="Last Name" DisplayMemberBinding="{Binding Path=LastName}"/>
<GridViewColumn Header="start" DisplayMemberBinding="{Binding Path=startHR}"/>
<GridViewColumn Header="finish" DisplayMemberBinding="{Binding Path=finishHR}">
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</StackPanel>
and the code behind is :
class employeesGrid //: INotifyPropertyChanged
{
ObservableCollection<employiesData> _employeeCollection =
new ObservableCollection<employiesData>();
public employeesGrid()
{
_employeeCollection.Add(new employiesData{
EmployeeID = "World Of Warcraft",
FirstName = "Blizzard",
LastName = "Blizzard",
startHR = "2222",
finishHR = "dfs"
});
}
public ObservableCollection<employiesData> employeeCollection
{ get { return _employeeCollection; } }
}
public class employiesData
{
public string EmployeeID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string startHR { get; set; }
public string finishHR { get; set; }
}
}
where inside my main开发者_JAVA百科 window i am doing :
//constructor: InitializeComponent(); employeesGrid em = new employeesGrid();
1.can someone please guide me what am i doing wrong ? 2.INotifyPropertyChanged why should i use it ? how should i use it ?
thanku for gazing in my work it means a lot to me :)
lets say i want two sturctures like this in my program what would be the best implmantion ????
You never set your listviews' DataContext.
Try this in your window constructor:
InitializeComponent();
employeesGrid em = new employeesGrid();
this.DataContext = em;
- You need to bind your view's datasource to your class instance. In your constructor, do this:
this.DataContext = new employeesGrid();
- INotifyPropertyChanged is an interface that you should use if you want your UI to refresh it's content when the underlying content changes.
精彩评论