Course C# Advanced including WPF, MVVM and SQL Database

Lesson 01 Tuesday June 2nd (08:30 – 12:00)

Homework to finish before Lesson 01
Perform the following assignment using Visual Studio 2019:
Exercise: Creating an Object Oriented System for Drawing Shapes using C#
If certain topics appear to be unclear, an explanation of the different object oriented concepts used in this exercise can be found here:

Class Time
During this first lesson we will get acquainted with each other and discuss the topics of the course.
We will use the homework exercise mentioned above to perform a thorough recap of the C# Fundamentals course to see where we all stand knowledge wise and skill wise.
These recap topics will be discussed as well:

1. Generics

2. Delegates

Lesson 02 Tuesday June 9th (08:30 – 12:00)

Homework to finish before this lesson
Perform the parts 5, 6, 7 and 8 using Visual Studio 2019.
Exercise: Creating an Object Oriented System for Drawing Shapes using C#
For the parts 6 and 7 this article might be handy:

Class Time
The second lesson will start with a discussion of the homework. Other topics during class time:

3. Performing Operations Asynchronously

Lesson 03 Tuesday June 16th (08:30 – 12:00)

Homework to finish before this lesson
Perform the parts 9 and 10 using Visual Studio 2019 of this exercise:
Exercise: Creating an Object Oriented System for Drawing Shapes using C#
If there is nothing else for you to watch on Netflix, you could check out Async programming deep dive by Bart De Smet.

Class Time

4. Creating a Windows Desktop Application using WPF

First released as part of .NET Framework 3.0 in 2006

5. Working with XML and XAML

6. Creating Modern and Advanced GUIs using WPF

Lesson 04 Tuesday June 23th (08:30 – 12:00)

Homework to finish before this lesson
Perform the parts 11, 12 and 13 of this exercise:
Exercise: Creating an Object Oriented System for Drawing Shapes using C#

Class Time

  • Homework Discussion
  • Visual Studio Tip of the Day: Vertical Selection + Editing
    it gets even better thanks to Karel’s tip 💡 Multi-line and multi-cursor editing
  • Some Key WPF Concepts
    • A Dependency Property is a property whose value depends on multiple sources, such as animation, data binding, styles, or visual tree inheritance. A Dependency Property also has the built-in feature of providing notification when the property has changed. Their values are not stored in the local object but (only changed) properties are stored in a dictionary of key/value pairs which is provided by the DependencyObject class.
    • Attached Properties are a special kind of Dependency Properties that are settable on a different object than the one that exposes it. An example of attached property is a StackPanel using DockPanel.Dock=”Top” or a Button using Canvas.Left=”120″.
  • Content Controls are controls that can contain a single item in their Content property. This can of course also be one of the panel controls…
    Below are some examples of Content Controls:
  • Examples of other types of controls can be found here
  • ItemsControls contain a collection of child objects. The ItemSource or Items property specifies the source collection of child objects.
    • 💡 If you specify a value for the ItemsSource property, the Items collection is made read-only and fixed-size, which means that you cannot add items to the collection directly.

    Below are some examples of ItemsControls:

    • ComboBox
    • ListBox
      👓 WPF101 > ItemControlEventsDemo
      👓 WPF101 > CSharpCodeInXAMLDemo
    • 💡 Example of how to display selected text from both ComboBox and ListBox in a Label:
    •       private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                if (myLabel != null)
                {
                    // Selector is a base class of both ComboBox and ListBox
                    // Both ComboBoxItem and ListBoxItem derive from ContentControl
                    myLabel.Content = ((sender as Selector)?.SelectedValue as ContentControl)?.Content.ToString();
                }
            }
            
  • WPF Resources
    👓 WPF101 > ResourcesDemo
    • Defining Resources by Using XAML
    • Defining Resources Programmatically
    • Referencing Resources in XAML
      • reference as StaticResource
      • reference as DynamicResource
      • The most common markup extensions used in WPF programming are those that support resource references (StaticResource and DynamicResource)

        💡 you could also paint using a Gradient Brush

  • Styles
    👓 WPF101 > StylesDemo
  • You can think of a style as a convenient way to apply a set of property values to more than one element

Lesson 05 Thursday July 2nd (08:30 – 12:00)

Homework to finish before this lesson
Complete the following assignment using Visual Studio 2019:
Exercise: Creating a Visual Solar System using WPF

Class Time

  • Homework Discussion
  • Visual Studio Tip of the Day: Run To Cursor
  • Control Templates
    👓 WPF102 > ControlTemplatesDemo
    👓 WPF102 > SeparateControlTemplateDemo
  • By setting the Template property to another instance of a Control Template, you can completely replace the appearance (visual tree) of a control.

    In many cases, Control Templates give you sufficient flexibility so that you do not have to implement your own Custom Controls

  • Routed Events
    👓 WPF102 > TunnelingAndBubblingDemo
    👓 WPF102 > RoutedEventsDemo
  • Routed events are events that can invoke handlers on multiple listeners in an element tree, instead of invoking them only on the object that raised the event. This behavior is largely invisible if you are handling an event on the element where it is raised, but becomes powerful if you use any of these scenarios: defining common handlers at a common root, compositing your own control, or defining your own custom control class.

  • Commands
  • Data Binding
  • Data Binding enables a clean separation of business logic from UI

    • Introduction
    • Binding Markup Extension
    • Data Binding Modes
      👓 WPF102 > BindingToControlsDemo
      💡 In general, user-editable control properties, such as those of text boxes and check boxes, default to two-way bindings, whereas most other properties default to one-way bindings.
      • OneWay
      • TwoWay
      • OneWayToSource
      • OneTime

Lesson 06 Tuesday July 7th (08:30 – 12:00)

Homework to finish before this lesson
Complete parts 6 and 7 of our solar system assignment:
Exercise: Creating a Visual Solar System using WPF

Class Time

  • Homework Discussion
  • Visual Studio Tip of the Day: C# Interactive Window
  • DataContext
    • Specify the Binding Source using C# (via Code Behind)
      👓 WPF103 > BindingToSingleObjectDemo
    • Specify the Binding Source using XAML
      👓 WPF103 > BindingToSingleObjectDemoXAMLTwoStep
      👓 WPF103 > BindingToSingleObjectDemoXAMLOneStep
  • The UpdateSourceTrigger Property
    👓 WPF103 > UpdateSourceTriggerDemo
  • Property Change Notification
  • Converting Data

Lesson 07 Tuesday July 14th (08:30 – 12:00)

Homework to finish before this lesson
Complete parts 8 and 9 of our solar system assignment:
Exercise: Creating a Visual Solar System using WPF

Class Time

Lesson 08 Tuesday July 21th (08:30 – 12:00)

Homework to finish before this lesson
Complete parts 10, 11, 12, 13, 14, 15, 16 and 17 of our solar system assignment:
Exercise: Creating a Visual Solar System using WPF

Class Time

  • Homework Discussion
  • Visual Studio Tip of the Day: Searching inside Visual Studio plus Navigate/GoTo (Ctrl+,)
  • Binding to Collections
    • 👓 WPF105 > SelectedValuePathDemo
    • 👓 WPF105 > BindingToACollectionDemo
    • Observable Collections
      💡 ObservableCollection(T) implements INotifyCollectionChanged to provide notifications when items are added or removed or the whole collection is changed. When a control is bound to an ObservableCollection, WPF automatically adds a CollectionChanged event handler to that ObservableCollection’s events.
      💡💡 Each object in the collection must implement INotifyPropertyChanged. Otherwise changes to individual object properties are not broadcasted.
      👓 WPF105 > ObservableCollectionDemo
      👓 WPF105 > ObservableCollectionDemoXAML
      • 💡 this demo also uses a so-called ObjectDataProvider
      • An ObjectDataProvider allows us to specify a method name, pass arguments and invoke it from XAML

    • Collection Views
      💡 A Collection View is a wrapper around a collection that enables sorting, filtering and grouping without manipulating the underlying source collection. All collections have an associated default collection view. The binding engine always accesses the collection by using the associated view.
      👓 WPF105 > CollectionViewDemo
    • Data Templates
      👓 WPF105 > DataTemplateComboBoxDemo
      The ListView control makes heavy use of DataTemplates.
      💡 the _Starter.xaml file in every 👓 WPF10x demo solution contains both a Collection View and a Data Template
  • Showing Sample Data while Designing
  • Appendix: Summary of WPF Class Hierarchy

7. The Model-View-ViewModel (MVVM) Software Architectural Pattern

  • What Wikipedia has to say
  • Introducing the MVVM Pattern
  • Getting started with MVVM WPF
  • Fundamental equation of MVVM: View.DataContext = ViewModel
    also called ‘Marrying the View and the ViewModel’

  • Commands Revisited
  • All user controls that implement the ICommandSource interface (e.g. Buttons, MenuItems) support a Command property that will be invoked when the control’s default action occurs.

    Commands are simply objects that implement the ICommand interface. Or, put another way, Commands are messages from the View to your View Model

  • A more complete MVVM Example
    👓 NorthwindTradersMVVM
    • the NorthwindTradersMVVM Demo – Notes, Tips & Tricks document
    • including some basic Unit Tests

      The name of your Unit Test Method should consist of three parts:

      • the name of the method being tested
      • the scenario under which it is being tested
      • the expected behavior when the scenario is invoked

      💡 some examples are:

      • Withdraw_ValidAmount_ChangesBalance()
      • Withdraw_AmountMoreThanBalance_Throws()
      • Add_SingleNumber_ReturnsSameNumber()
      • Add_MaximumSumResult_ThrowsOverflowException()

Lesson 09 Tuesday July 28th (08:30 – 12:00)

Homework to finish before Tuesday September 1st, 2020 (09:00 CEST)
Complete the final assignment: Exercise: Final Assignment

Class Time

  • Visual Studio Tip of the Day: Code Editor Keyboard Shortcuts
  • 8. Introduction to Databases and SQL

    9. How to Design a Relational Database

    10. Implementing a database using Microsoft SQL Server 2014
    💡 in case of error message “Saving changes is not permitted”

  • Create a Database in SQL Server Management Studio
  • Create Tables
  • Create a foreign key relationship in Table Designer
  • some extracurricular articles on numerical data types:
  • 11. Perform Create/Read/Update/Delete (CRUD) Operations on SQL Server

  • The original ADO.NET low-level Data Access Library
  • ADO.NET Entity Framework
    Microsoft’s implementation of an Object-Relational Mapping (ORM) framework (since August 2008)
  • Final Lesson 10 Tuesday August 4th (08:30 – 12:00)

    Class Time

  • Visual Studio Tip of the Day: Conditional and Hit Count Breakpoints
         👓 BreakpointsDemo
  • Development Approaches with Entity Framework
         ⧉ this figure illustrates the choices in Visual Studio
         💡 server names: (localdb)\MSSQLLocalDB or (local)\SQLEXPRESS
         💡 Install latest version (now 6.4.4): Install-Package EntityFramework
         💡 Logging and intercepting database operations
  • 12. Language-Integrated Query (LINQ)

  • Behaviors in WPF
  • A behavior encapsulates functionality into a reusable component that can be attached to View elements. Behaviors keep the MVVM pattern intact.

    💡 You can also use an Attached Property to provide a service, which is often referred to as Attached Behavior

  • Attached Behavior versus Blend Behaviors
    • Attached Behavior
      👓 WPF106 > AttachedBehaviorDemo
    • Blend Behavior
    • Blend Behaviors are meant to give interaction designers more flexibility to design complex user interactions without writing any code.

      • Since 2018 XAML Behaviors for WPF is available as NuGet package
        👓 WPF106 > BlendBehaviorDemo
        👓 WPF106 > AnotherBlendBehaviorDemo
        👓 WPF106 > StoryboardAnimationDemo
  • BackgroundWorker Class
         since .NET 2.0 (2006)
  • Task Parallal Library (TPL)
         since .NET 4.0 (2010)
  • Validation using INotifyDataErrorInfo and Validation Attributes
  • Recap: Benefits of using MVVM
    • Collaborative working
    • Ease of testing
    • Ease of maintainability
    • Transparent Communication
    • In the Microsoft solution stack, the binder is a markup language called XAML

      recommended book about design patterns in general: Head First Design Patterns

  • Action vs Func vs Predicate in C#
         👓 ActionFuncPredicateDemo