I want my DataGrid in WPF show nested classes into my objects. I'm using NHibernate to retrieve data.
My Model class:
public class PublishedBook
{
public virtual long ID { get; set; }
public virtual string Title { get; set; }
public virtual YearSemester BookYearSemester { get; set; }
public override string ToString()
{
return string.Format("{0} ({1})", Title, BookYearSemester);
}
}
public class YearSemester
{
public virtual long ID { get; set; }
public virtual string Description { get; set; }
public override string ToString()
{
return Description;
}
}
My Repository class:
public class PublishedBookRepository : BaseRepository
{
public PublishedBookRepository(ISession objCurrentSession) :
base(objCurrentSession) { }
public IEnumerable<PublishedBook> GetAllPublishedBooks()
{
return base.CurrentSession
.CreateCriteria<PublishedBook>()
.List<PublishedBook>();
}
}
My XAML Code:
<DataGrid x:Name="dagtagridPublishedBooks" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Title" Binding="{Binding Title}" />
<DataGridTextColumn Header="YearSemester" Binding="{Binding YearSemester}" />
</DataGrid.Columns>
</DataGrid>
In the second column, the data isn't displayed. Anyone knows why? Thanks, guys!!