Using embedded MediaElement controls to play videos in WPF / MVVM

Essentially the same as these instructions, but using a purely MVVM approach and without the additional stop / start / pause etc buttons – the application just ‘sees’ the MP4 media file it needs to play and plays it upon startup. Step 1: Create a new WPF Application Step 2: Create the Main Window ViewModel …

Continue reading ‘Using embedded MediaElement controls to play videos in WPF / MVVM’ »

Running a WPF Progress bar as a background worker thread

How to run a WPF progress bar as a background worker thread. This code uses ICommand to respond to the user’s request to both and pause start the progress bar background process. Step 1: Create a new WPF application Step 2: Create the MainWindow.xaml user interface components Step 3: Create the ViewModel classes BaseViewModel.cs MainWindowViewModel.cs …

Continue reading ‘Running a WPF Progress bar as a background worker thread’ »

Binding a XAML control visibility to a ViewModel variable in WPF

Some instructions on how to bind the visibility of a XAML button control to a boolean value in a ViewModel class. 1. Create a new WPF application 2. Add the View Model class Right click your project folder and select Add > New Item > Class. Name your class MainWindowViewModel.cs: In your ViewModel class include …

Continue reading ‘Binding a XAML control visibility to a ViewModel variable in WPF’ »

Using RelayCommand / ICommand to handle events in WPF and MVVM

A step-by-step guide to using the RelayCommand class (based on ICommand) as means of handling user-initiated events in WPF / MVVM / XAML. 1. Create a new WPF application 2. Add the View Model class Right click your project folder and select Add > New Item > Class. Name your class MainWindowViewModel.cs: The MainWindowViewModel class …

Continue reading ‘Using RelayCommand / ICommand to handle events in WPF and MVVM’ »

Switching between WPF XAML views using MVVM DataTriggers

Related post: https://www.technical-recipes.com/2016/switching-between-wpf-xaml-views-using-mvvm-datatemplate/ This post addresses the problem of being able to switch between different views based on the property of a ViewModel class. To get started in Visual Studio, create a new WPF Application: So that when we build and run the application we have a blank window like this: To demonstrate how WPF …

Continue reading ‘Switching between WPF XAML views using MVVM DataTriggers’ »

Getting Started with C# WPF Applications

Some notes on how to create a simple Windows Presentation Foundation (WPF) application and get familiar with the Visual C# integrated development environment (IDE). Like Windows Forms applications, WPF applications can be developed by dragging controls from the Toolbox to the design editor. As well as having a designer, Properties window and Toolbox, the IDE …

Continue reading ‘Getting Started with C# WPF Applications’ »