我有一個DataGrid的顯示,定義如下:非常奇怪的問題:涉及數據
<DataGrid Name="dgResults"
IsReadOnly="True"
AutoGenerateColumns="True"
AllowDrop="False"
CanUserAddRows="False"
CanUserDeleteRows="False"
CanUserReorderColumns="True"
CanUserResizeColumns="True"
CanUserResizeRows="False"
CanUserSortColumns="False"
ColumnWidth="120"
Margin="15,10,10,10"
Visibility="Collapsed"
ItemsSource="{Binding}"/>
出於某種原因,沒有數據綁定到它時顯示。顯示正確數量的行,但它們都是空的。這是我的代碼:
dgResults.DataContext = dtTopTwoHundredResults.AsDataView();
dgResults.AutoGeneratingColumn += new EventHandler<DataGridAutoGeneratingColumnEventArgs>(dataGrid_AutoGeneratingColumn);
dgResults.Visibility = Visibility.Visible;
private void dataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
//Sets the DataGrid's headers to be TextBlocks, which solves a problem whereby underscore characters in the header are ignored.
TextBlock block = new TextBlock();
block.Text = e.Column.Header.ToString();
e.Column.Header = block;
}
這肯定不是與數據源的問題,因爲數據被包含在它裏面,它應該是。這只是DataGrid。這是它是如何顯示的,即正確的量行的,但沒有數據:
我用史努比,以找出是否該文本實際上是包含在DataGrid和我得到這個:
System.Windows.Data Error: 40 : BindingExpression path error: 'Employee identification number' property not found on 'object' ''DataRowView' (HashCode=51298929)'. BindingExpression:Path=Employee identification number. Foreign key to Employee.BusinessEntityID.; DataItem='DataRowView' (HashCode=51298929); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Error: 40 : BindingExpression path error: 'Employee identification number' property not found on 'object' ''DataRowView' (HashCode=51298929)'. BindingExpression:Path=Employee identification number. Foreign key to Employee.BusinessEntityID.; DataItem='DataRowView' (HashCode=51298929); target element is 'PropertyInformation' (HashCode=11239682); target property is 'Value' (type 'Object')
你甚至可以把空格放在綁定路徑中嗎? 「員工識別號碼」 – Andy
你是什麼意思@Andy?這心不是意味着是一個綁定路徑 - 這是列的名字 - 從微軟的AdventureWorks databasse –
移動到這個問題,作爲我發現這個問題是什麼:http://stackoverflow.com/questions/16041222/how-to-顯示內容與標點符號 –