I've got a SQL Server database up and running, initialized with EF6. I'm quite new to all three of these subjects and am struggling to fill up a datagrid using the SQL database.
In short, I realize I need to
1) Fill up an observable collection with data from the already existing database (Seeing as what the datagrid needs to do, I've determined an observable collection would
be my best choice)
2) Connect that collection to the datagrid
3) Bind all the columns for said datagrid
So far this is what I have.
View1.xaml
<DataGrid Grid.Row="2" Grid.RowSpan="3" x:Name="GameDatagrid" AutoGenerateColumns="False" ItemsSource="{Binding GameCollection}">
<DataGrid.Columns>
<DataGridTextColumn Header="GameID" Binding="{Binding GameID, Mode=OneWay}" Width="SizeToHeader" />
<DataGridTextColumn Header="Game Name" Binding="{Binding Name, Mode=OneWay}" Width="SizeToHeader"/>
</DataGrid.Columns>
</DataGrid>
View1.xaml.cs
public partial class View1 : UserControl
{
public ObservableCollection<Game> GameCollection { get; set; }
public View1()
{
InitializeComponent();
ObservableCollection<Game> GameCollection = new ObservableCollection<Game>();
GameDatagrid.ItemsSource = GameCollection;
}
And the object class
public class Game
{
public int GameID { get; set; }
public string Name { get; set; }
public ObservableCollection<Game> GameCollection { get; set;}
}
The attached viewmodel doesn't have anything of relevance as of yet.
I do realize that it probably shows nothing because the collection is empty, but what is the most efficient MVVM way to fill one up and use?
