First off, New to XAML and Programming in general. I am trying to populate a XAML Datagrid in the .cs file.
I have classes for each SQL table I'm using, holding properties that reference columns
public partial class TTDepartment
{
public TTDepartment()
{
this.TTEventLogs = new HashSet<TTEventLog>();
this.TTUserDepartments = new HashSet<TTUserDepartment>();
}
public string Department { get; set; }
public string Manager { get; set; }
public string ManagerEmail { get; set; }
public virtual ICollection<TTEventLog> TTEventLogs { get; set; }
public virtual ICollection<TTUserDepartment> TTUserDepartments { get; set; }
}
What I am doing currently is attempting to use LINQ queries on my classes to retrieve data, Like this
(I'm Aware there is likely a better way to do this) please help
private void GetDepartments()
{
using (var context = new CetusEntities())// New instance of Database class
{
var linqDept = context.TTDepartments.Where(s => s.Department != "" || s.Department != null); // Should return All Departments from TTDepartments Class?
//Populate colDept in Datagrid with results from LINQ
}
}
Here is the XAML for Datagrid
<DataGrid x:Name="dgDept" Height="200">
<DataGrid.Columns>
<DataGridTextColumn x:Name="colDept" Binding="{Binding Source = {StaticResource Department}}" Header="Department"></DataGridTextColumn>
<DataGridTextColumn x:Name="colMan" Binding="{Binding Source = {StaticResource Department}}" Header="Manager"></DataGridTextColumn>
<!--<DataGridTextColumn Header="Email"></DataGridTextColumn>-->
</DataGrid.Columns>
</DataGrid>
Your query should look like this:
Also, verify that you actually have data in your db. Then debug.
//set the datagrid source to test.
XAML Example: