我正在跟隨一些例子,我無法在我的數據網格中顯示數據。值得一提的是,我在從db中獲取數據時,看着debuger。WPF不顯示數據網格內的數據
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>
更新
- 我已經改變到的AutoGenerateColumns = 「真」 在MainWindow.xaml
- 新增了MRDataGrid.ItemsSource =屬性;在xaml.cs代碼
- 我應該在MainWindow.xaml中的ItemSource中放置什麼?
你沒有設置ItemsSource – Paparazzi 2013-04-08 18:44:25
嗯......嘗試'AutoGenerateColumns =「True」'? – McGarnagle 2013-04-08 18:44:27
你將DataContext分配給MRDataGrid聽起來像是一個綁定/路徑問題你有 – MethodMan 2013-04-08 18:44:38