我正在从实体模型生成一个DataGrid,后面的代码非常简单。但是现在我试图以MVVM模式绑定它,我似乎无法弄清楚如何返回通用列表。
从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()
}
发送到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>
任何输入都将非常感谢!!
答案 0 :(得分:1)
我通常使用IList
或IEnumerable
,但我想您也可以返回object