UWP, C#, XAML, MVVM, EF and SQLite - Code Red and Green (2023)

UWP, C#, XAML, MVVM, EF and SQLite - Code Red and Green (1)

Last week, I describe a programming project I started this year. It's a time tracking app that not only tracks what you spend your time on, but also tries to influence those decisions.

I'll get into the initial coding details next week. This week I'm going to expand the tech stack I'm working on.

Universal Windows Platform (UWP)

When choosing a technology stack for your app, the first decision to make is which devices you want to run it on. This determines the target audience and influences the user interface and subsequent technology choices.

The target audience for my app are knowledge workers (such as developers) who want to track how much time they spend on their desktop or laptop. My priority is not to keep track of the total time for all my daily activities. Therefore, mobile or tablet based apps are currently not included.

(Video) Intro to UWP (Universal Windows Platform) Apps in C#

What do developers use on their desktops and laptops? This2016 Stack Overflow Developer SurveyName the four types of desktop operating systems:

  • Mac OS X (used by 26.2% of respondents)
  • Windows version (52.2%)
  • Linux distributions (21.7%)

Windows remains the clear leader, although research reports show year-over-year trends in favor of Mac OS X. However, since I am a Windows user, I will elaborate on this option.

For the latest version of Windows, Windows 10, this is called the latest application architectureUniversal Windows platform(UWP). Part of UWP's appeal is that it can target multiple devices (phones, tablets, and desktops, for example) using a single codebase. This might work for my app at some point, but the main benefit right now is that UWP is the modern choice for building Windows 10 desktop apps.

Back to the developer survey results: 20.8% of respondents use Windows 10 as their development environment. Another 8.4% use Windows 8.x. This is a notoriously unpopular version of Windows, so I suspect many of these users are considering an upgrade. This equates to 29.2% of developers likely to test the app soon. That's not an overwhelming number, nor is it a huge number for a for-profit company, but it's far from a niche market. As an open source experiment that I want to use for my own purposes, it makes sense.

Why not create a web application that can run on any platform? For single-user applications, this is not a good compromise. Desktop applications are easier to create and provide more direct access to operating system services. This can be useful for advanced functions, such as getting a list of running programs and open web pages. So is UWP.

(Video) .NET MAUI Data Binding with MVVM & XAML [5 of 8] | .NET MAUI for Beginners

C♯

UWP apps can be developed in many programming languages, but C# was an easy choice for me. It's a language I use a lot, it doesn't have the syntax problems of Java and there are plenty of examples online of how to use it to build UWP apps.

Extensible Application Markup Language (XAML)

XAMLIt is a markup language used to define the user interface of UWP applications, just as HTML is used to describe web pages. XAML can be used to define buttons, text boxes, grids (for layout), lists, and other controls. He can alsotie up.

Binding is a method of linking an XAML control to a method or property in code. For example, a text box can be bound to a property so that when the user types in the text box, the property is updated. Another common connection is between a method in code and a button click event. This method is called when the user clicks the button.

Visual Studio has an XAML editor that keeps the visual design in sync with its XAML: you can drag and drop controls into the visual editor and the XAML markup is updated automatically. You can update the XAML manually and see the effect in the visual editor. This provides both the convenience of drag-and-drop scheduling and the benefit of text-based formatting files that can be maintained in a version control system.

Model-View-ViewModel (MVVM)

UWP does not enforce any specific program design. Developers are free to use the platform as they see fit. However, some designs fit better than others.Model-View-ViewModel(MVVM) is an architectural pattern designed for use with Windows Presentation Foundation (WPF), the predecessor of UWP, which also uses XAML to define the user interface.

(Video) 01 - XAML for Windows 10 Layout - Fundamentals

The purpose of MVVM is to divide application code into groups of related components, each with a specific role. Here's how MVVM works in UWP apps:

  • ItModelHandles business logic and database communications.
  • Itmodel viewTake data from a model and organize or format it in a way that is convenient for the user interface.
  • ItdisplayDefine the user interface. The data that the UI needs to read and write comes from the ViewModel via the data connection.

Separating these three concerns allows developers to focus on one thing at a time when deploying an application. Or for larger projects, multiple developers can work on one system while avoiding code conflicts. It also helps with unit testing as components are easier to test individually.

Entity Framework (EF)

A time-tracking application must store data such as job names and start/end times. Since the computer crashes and restarts, simply storing them in memory is not enough. We need some kind of persistent data store and the model needs a way to talk to that data store.

For UWP apps, the recommended way is to connect the model to the databaseEntity framework(EF). EF is oneObject relational mappingframework (ORM), a method of accessing a relational database using an object-oriented programming language without manually writing code to convert between the object model and the data model. Because object-oriented programs and relational databases represent data differently, using an ORM for conversion can simplify the programming process. It allows developers to think in terms of an object model without worrying about how it will be represented in the database.

There are some performance pitfalls to be aware of when using an ORM. Compilers can generate assembly code faster than almost anyone, while ORMs tend to generate less than ideal queries. Knowing what's going on under the hood can help prevent such problems.

(Video) Conditional XAML in UWP

she asked

We've reached the bottom of the technology stack: the database.she askedis a popular embedded database engine recommended for local UWP app data storage. Besides coming with Windows 10, SQLite has been used by many common programs over the years, including Chrome and Firefox.

The Entity Framework project maintains a database provider that allows EF to be used with SQLite databases.

technology

Of all the components of this planned technology stack, I think UWP is the most dangerous. Although it has been around for a few years, it is still very new compared to other .NET options for building Windows desktop applications, such as Windows Presentation Foundation (WPF) and Windows Forms.

Fortunately, WPF also plays well with other patterns and components (C#, XAML, MVVM, EF, and SQLite). If I run into limitations that UWP can't overcome, I can always switch to WPF without wasting too much work.

Next week: In the code.

(Video) C# Course - Fundementals of building desktop and mobile UIs with C# and XAML - part 1

(Image source: designed+SQLite-logo(Public space))

FAQs

How to use SQLite database in UWP? ›

We recommend that you use either the Entity Framework Core or the open-source SQLite library built by Microsoft.
  1. Entity Framework Core. ...
  2. SQLite library. ...
  3. Prepare the data access class. ...
  4. Initialize the SQLite database. ...
  5. Insert data into the SQLite database. ...
  6. Retrieve data from the SQLite database.
Oct 20, 2022

Is WPF part of UWP? ›

There might be a misconception that UWP is a framework like WinForms and WPF but that is not the case. UWP is a much broader solution but has now been deprecated by Microsoft.

How to use SQLite database in Windows application C#? ›

Getting Started with SQLite from a .

Open Visual Studio, select new project, and, in Visual C#, select “Console Application” and provide the name as SQLiteDemo. Click OK. To connect SQLite with C#, we need drivers. Install all required SQLite resources from the NuGet package, as pictured in Figure 1.

How to connect SQLite to database? ›

Connecting to SQLite
  1. Open the connections page in preferences, see managing connections for more information.
  2. Click the Add new Connection button at the top of the connections page.
  3. Select SQLite from the list.
  4. Give a Connection name for your own internal reference.

Is Microsoft discontinuing UWP? ›

Microsoft continues to baby-step around the obvious, but it has officially deprecated the Universal Windows Platform (UWP) as it pushes the desktop-focused Windows App SDK (formerly called Project Reunion) and WinUI 3 as the future of Windows application development.

Is UWP outdated? ›

No. UWP and WinUI 2 are still supported and will receive bug, reliability, and security fixes.

Is WPF being phased out? ›

According to the documentation Overview - Product end of support, there are no plans to remove wpf. So it will be supported.

How to display data from database in C# Windows application? ›

Step 1: Make a database with a table in SQL Server. Step 2: Create a Windows Application and add DataGridView on the Form. Now add a DataGridView control to the form by selecting it from Toolbox and set properties according to your needs.

How to connect database with C# in Visual Studio? ›

On the View menu, select Other Windows > Data Sources. In the Data Sources window, click Add New Data Source. The Data Source Configuration Wizard opens. Select Database on the Choose a Data Source Type page, and then select Next.

How to display data from database in C# Console Application? ›

Step 1: Create a new project using "File" -> "New" -> "Project..." then select "Console Application". Step 3: See the following screen; select "MySQL Wamp Server database" > "Student data". Now retrieve data using the MySQL Wamp Server database. I hope this article is useful.

How do I access SQLite database in Windows? ›

How to Install SQLite On Windows
  1. Step 1: Download the SQLite ZIP File. You can download this file from the SQLite website here.
  2. Step 2: Unzip the file. Right click on the ZIP file and extract it to C:\SQLite.
  3. Step 3: Open SQLite. Double click the sqlite3 file to open the software:
Feb 8, 2020

What is the default port for SQLite? ›

Enter the SQLite Importer port. The default port is 8191.

How do I access a local SQLite database? ›

Install using the zipped SQLite tools for Linux
  1. unzip sqlite-tools-linux*.zip. Navigate into the extracted archive using cd . ...
  2. ./sqlite3. If you run the command without any arguments, SQLite will use an in-memory database: ...
  3. .open --new test.db. ...
  4. .open test.db. ...
  5. .quit. ...
  6. ./sqlite3 test.db.

How to deploy SQLite database? ›

3 Steps to Seamlessly Deploy SQLite Projects on Desktop, Web &...
  1. Adding the database file. You probably created your SQLite database file using an external editor; so first add that file to your Xojo project. ...
  2. Copying the database file to a “Working” folder. ...
  3. Simplifying the process.
Mar 17, 2020

How to connect to SQLite via ODBC? ›

Connecting Excel to SQLite with Get & Transform (Power Query)
  1. Click the Data in Excel, then expand the Get Data drop-down list. ...
  2. In the From ODBC dialog, choose your data source name (DSN). ...
  3. If you're using a database username or password, select Database and enter your credentials in the dialox bog, then click Connect.

How to import SQLite database in Visual Studio? ›

Working with SQLite
  1. Open the integrated terminal and browse to "/"
  2. Create a folder called "data"
  3. Move into that folder and create a new SQLite database with sqlite3 lamp.db.
  4. Connect to the database with the SQLite Extension.
  5. Create a new table called "colors"
  6. Insert a few records.
  7. Select the records back out.

How to connect to SQLite database with Nodejs? ›

Connecting To SQLite Database Using Node. js
  1. First, import the sqlite3 module.
  2. Second, call the Database() function of the sqlite3 module and pass the database information such as database file, opening mode, and a callback function.

Why not use SQLite in production? ›

SQLite is a serverless database, it doesn't provide direct network access to its data. This access is built into the application. If the data in SQLite is located on a separate machine from the application, it will require a high bandwidth engine-to-disk link across the network.

What is the correct way to create database in SQLite? ›

Create A New Database
  1. At a shell or DOS prompt, enter: "sqlite3 test.db". This will create a new database named "test.db". (You can use a different name if you like.)
  2. Enter SQL commands at the prompt to create and populate the new database.
  3. Additional documentation is available here.
Jan 8, 2022

How to setup SQLite database locally? ›

Install using the zipped SQLite tools for Linux
  1. unzip sqlite-tools-linux*.zip. Navigate into the extracted archive using cd . ...
  2. ./sqlite3. If you run the command without any arguments, SQLite will use an in-memory database: ...
  3. .open --new test.db. ...
  4. .open test.db. ...
  5. .quit. ...
  6. ./sqlite3 test.db.

Does SQLite support ODBC? ›

ODBC Driver for SQLite can be used with 32-bit and 64-bit applications on both x32 and x64 platforms, so there is no need to additionally configure the driver, applications or environment.

How to create ODBC for SQLite? ›

Windows DSN Configuration - ODBC Driver for SQLite
  1. Open the ODBC Data Source Administrator. ...
  2. Select the User DSN or System DSN tab. ...
  3. Click Add. ...
  4. Select Devart ODBC Driver for ASE and click Finish. ...
  5. Enter the connection information in the appropriate fields.
  6. You may test the connectivity by clicking Test Connection.

How to setup ODBC connection to SQL database? ›

  1. Click Start and select Settings > Control Panel > Administrative Tools.
  2. Double-click Data Sources (ODBC) to open the ODBC Data Source Administrator.
  3. Select the System DSN tab.
  4. Click Add.
  5. Select SQL Server and click Finish.
  6. Complete the DSN Configuration wizard (see example screen shots below)

How to visualize SQLite database? ›

Import & Visualization of existing SQLite databases
  1. Select the database file. ...
  2. Then click the Connect and load database structure button.
  3. The result after successful import: a graphical representation in the form of an ER diagram.
  4. You can also update your SQLite ER diagram in Luna Modeler.

How to check if a table exists in SQLite C#? ›

SQLite - Checking whether a table exists
  1. SELECT name FROM sqlite_master WHERE type='table' AND name='table_name';
  2. CREATE TABLE IF NOT EXISTS table_name (table_definition);
  3. DROP TABLE IF EXISTS table_name;
Apr 21, 2018

How to use Entity Framework with SQLite? ›

Entity Framework
  1. Step 1: Nuget packages. Create a new console project in visual studio. ...
  2. Step 2: Model generation. To generate the model, you need to use also the command line. ...
  3. Step 3: Check your generated classes. ...
  4. Step 4: Write your cruds. ...
  5. Step 4: And finally check your database.
Dec 13, 2022

How to query SQLite with Node js? ›

Querying Data in SQLite Database from Node. js Applications
  1. Open a database connection.
  2. Execute a SELECT statement and process the result set.
  3. Close the database connection.

How to connect node to SQL database? ›

Install MySQL Driver
  1. C:\Users\Your Name>npm install mysql.
  2. var mysql = require('mysql');
  3. Run "demo_db_connection.js" C:\Users\Your Name>node demo_db_connection.js.
  4. Connected!
  5. con. connect(function(err) { if (err) throw err; console. log("Connected!" ); con. query(sql, function (err, result) { if (err) throw err;

How to connect SQLite with JavaScript? ›

js and SQLite are separate entities, but both can be used together to create powerful applications. First, we need to link them together by requiring the sqlite3 module. Once we have required this module in our JavaScript, it will give us access to methods to perform various actions with the database.

Videos

1. Building Apps Using XAML, UWP, and .NET Core – Installation and Commands of .NET Core | packtpub.com
(Packt )
2. 23.Learn WPF in small Steps: Styles and resources dictionary
(mahesh panhale)
3. Rapidly Construct LOB Applications with UWP and Visual Studio 2017
(Microsoft Developer)
4. WPF Controls | 24 -RadioButton | HD | RadioButton in WPF
(tips'n tricks)
5. Learn C# with CSharpFritz - MVVM with .NET MAUI
(dotnet)
6. Xamarin Forms Tutorial: Build Native Mobile Apps with C#
(Programming with Mosh)

References

Top Articles
Latest Posts
Article information

Author: Melvina Ondricka

Last Updated: 09/15/2023

Views: 5281

Rating: 4.8 / 5 (68 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Melvina Ondricka

Birthday: 2000-12-23

Address: Suite 382 139 Shaniqua Locks, Paulaborough, UT 90498

Phone: +636383657021

Job: Dynamic Government Specialist

Hobby: Kite flying, Watching movies, Knitting, Model building, Reading, Wood carving, Paintball

Introduction: My name is Melvina Ondricka, I am a helpful, fancy, friendly, innocent, outstanding, courageous, thoughtful person who loves writing and wants to share my knowledge and understanding with you.