I am generating a DataGrid from an Entity Model, which was very simple in the code behind. But now that I am trying to bind it in an MVVM pattern, I can't seem to figure out how to return a generic list.
From the ModelView:
public ??? LoadMoviesMethod()
{
ObjectQuery<MovieTable> _movies = dataEntities.MovieTables;
var query =
from MovieTable in _movies
where MovieTable.Rating == "R"
orderby MovieTable.id
select new { MovieTable.Title, MovieTable.Rating, MovieTable.Stars, MovieTable.ReleaseYear };
??? MoviesList = query.ToList();
return MoviesList;
//where as the code behind was simply gridName.ItemsSource = query.ToList()
}
Sending into the DataGrid:
<UserControl x:Class="MovieMockup.MovieMockupListView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="300">
<DataGrid ItemSource="{Binding MovieMockupListModel.MoviesList}">
</DataGrid>
</UserControl>
Any input would be greatly appreciated!!
我通常使用IList
或IEnumerable
,尽管我想您也可以返回object
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.