Reputation: 14145
I'm following some example from and I cannot display data inside my datagrid. Worth to mention is that I'm getting data from db when looking inside debuger.
MainWindow.xaml.cs
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
public partial class MainWindow : Window
{
private void Window_Loaded(object sender, RoutedEventArgs e)
{
using (session...)
{
using (transaction...)
{
var properties = new List<MyProperty>();
// this variable is populated inside debugger
properties = session.Query<MyProperty>().ToList();
if (properties != null)
{
MRDataGrid.Columns[0].Visibility = System.Windows.Visibility.Hidden;
MRDataGrid.Columns[1].Visibility = System.Windows.Visibility.Hidden;
MRDataGrid.Columns[8].Visibility = System.Windows.Visibility.Hidden;
}
}
}
}
}
MainWindow.xaml
<Window x:Class="MyProject.WPF.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"
WindowStartupLocation="CenterScreen" BorderBrush="Black"
Background="AntiqueWhite" ResizeMode="NoResize"
Loaded="Window_Loaded">
<Grid>
<DataGrid AutoGenerateColumns="False" Height="202" HorizontalAlignment="Left" Margin="22,82,0,0"
Name="MRDataGrid" VerticalAlignment="Top" Width="461" ItemsSource="{Binding}"/>
</Grid>
</Window>
Update
Upvotes: 0
Views: 2276
Reputation: 45096
properties = session.Query().ToList();
MRDataGrid.ItemsSource = properties;
Upvotes: 0
Reputation: 11040
You're not setting any context for ItemsSource="{Binding}"
to work with.
Do something like myDataGrid.DataContext=...
or bind the data context or change the {Binding}
to point where you need it
Such as:
if (properties != null)
{
myDataGrid.ItemsSource = properties;
...
Upvotes: 1
Reputation: 838
Your datagrid doesn't have columns. You either need to declare them yourself or set AutoGenerateColumns="True"
You also need to assign the item source like Sten Petrov said
Upvotes: 0