我正在遵循一些示例,但我无法在我的数据网格中显示数据。值得一提的是,我在查看调试器时从 db 获取数据。
主窗口.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;
}
}
}
}
}
主窗口.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>
更新
- 我已在 MainWindow.xaml 中更改为 AutoGenerateColumns="True"
- 添加了 MRDataGrid.ItemsSource = 属性;在 xaml.cs 代码中
- 我应该在 MainWindow.xaml 的 ItemSource 中放什么?