Differences between revisions 1 and 10 (spanning 9 versions)
Revision 1 as of 2021-02-22 02:53:02
Size: 1563
Editor: scot
Comment:
Revision 10 as of 2021-03-31 22:08:08
Size: 1820
Editor: scot
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= Directions for 2/22/2021 CPTR 319 = = Example WPF project using C# .NET Core 3.1 =
Line 3: Line 3:
Create a .NET Core WPF application
Create a folder in the project called "Database"
Add the BibleBeliefs.DB file to the new "Database" folder.
Set the file to be copied to the output folder if newer.
== Getting Started ==

This is just the start of the project. Much of the work can be seen on [[https://github.com/scotpatti/BibleBeliefs|github]].

 *
Create a .NET Core WPF application
 * Create a folder in the project called "Database"
 * Add the [[attachment:BibleBeliefs.db|BibleBeliefs.DB]] file to the new "Database" folder.
 * Set the file to be copied to the output folder if newer.
Line 10: Line 14:
 * Microsoft.EntityFrameworkCore
 * Microsoft.EntityFrameworkCore.Sqlite
 * Microsoft.EntityFrameworkCore.Tools
 * Microsoft.!EntityFrameworkCore
 * Microsoft.!EntityFrameworkCore.Sqlite
 * Microsoft.!EntityFrameworkCore.Tools
Line 22: Line 26:
{{{#!highlight xml
Line 23: Line 28:
}}}

Add the Data Context

Example WPF project using C# .NET Core 3.1

Getting Started

This is just the start of the project. Much of the work can be seen on github.

  • Create a .NET Core WPF application
  • Create a folder in the project called "Database"
  • Add the BibleBeliefs.DB file to the new "Database" folder.

  • Set the file to be copied to the output folder if newer.

Add the following nuget packages:

  • Microsoft.EntityFrameworkCore

  • Microsoft.EntityFrameworkCore.Sqlite

  • Microsoft.EntityFrameworkCore.Tools

PM> Scaffold-DbContext "DataSource=.\DataBase\BibleBeliefs.db;" Microsoft.EntityFrameworkCore.SQLite -OutputDir "Database" -ContextDir "Database"

Add a Data Context to the xaml

Add a namespace for the ViewModels directory

   1 xmlns:viewmodels="clr-namespace:BibleBeliefs.ViewModels"

Add the Data Context

   1 <Window.DataContext>
   2      <viewmodels:MainViewModel/>
   3 </Window.DataContext>

Adding Data to the application

Now add the Grid

   1     <Grid>
   2         <Grid.ColumnDefinitions>
   3             <ColumnDefinition Width="250" />
   4             <ColumnDefinition Width="*" />
   5         </Grid.ColumnDefinitions>
   6         <Grid.RowDefinitions>
   7             <RowDefinition />
   8         </Grid.RowDefinitions>
   9         <DataGrid Grid.Row="0" Grid.Column="0" 
  10                   ItemsSource="{Binding Topics}" 
  11                   AutoGenerateColumns="False" 
  12                   SelectedItem="{Binding SelectedTopic}">
  13             <DataGrid.Columns>
  14                 <DataGridTextColumn Header="Topic" Binding="{Binding Topic}"  Width="*"/>
  15             </DataGrid.Columns>
  16         </DataGrid>
  17     </Grid>

ProgrammingLinks/WpfDatabaseExample2021 (last edited 2021-03-31 22:08:08 by scot)