WPF Datagrid cells empty
I'm having a really weird problem using the DataGrid control in WPF. After I set the ItemsSource of the DataGrid in code, the rows get generated but the cells are completely empty! I've never had this problem before using DataGrids, and I know that the bindings are working because I have another application that does something similar and it works on there. Also I tried having it auto generate my columns for me and it still doesn't work, in fact no columns are even generated. Below is my DataGrid in XAML, my code to populate the DataGrid, and my model.
Note: FindMoviesByName returns MovieInfo[]
<DataGrid x:Name="dgdMovies" AutoGenerateColumns="False" MaxHeight="450"
ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Auto">
<DataGrid.Columns>
<DataGridTextColumn Header="Movie Title" Width="150" Binding="{Binding Title}"></DataGridTextColumn>
<DataGridTextColumn Header="IMDB Location" Width="150" Binding="{Binding ImdbUrl}"></DataGridTextColumn>
<DataGridTextColumn Header="Genre" Width="150" Binding="{Bindin开发者_开发知识库g Genre}"></DataGridTextColumn>
<DataGridTextColumn Header="MPAA Rating" Width="150" Binding="{Binding MpaaRating}"></DataGridTextColumn>
<DataGridTextColumn Header="Personal Rating" Width="150" Binding="{Binding PersonalRating}"></DataGridTextColumn>
<DataGridTextColumn Header="Critics Rating" Width="150" Binding="{Binding CriticsRating}"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
var results = _updateService.FindMoviesByName(txtSearch.Text);
lblResults.Content = results.Length + " Results!";
dgdMovies.ItemsSource = results;
[DataContract]
public class MovieInfo
{
[DataMember] public string Title;
[DataMember] public string ImdbUrl;
[DataMember] public Genre Genre;
[DataMember] public MpaaRating MpaaRating;
[DataMember] public int CriticsRating;
[DataMember] public int PersonalRating;
}
Those are fields, not properties. Databinding only works with properties.
精彩评论