Handle Protocol Activation and Redirection in Packaged AppsPosted: May 10, 2019 Filed under: .NET, MSIX, WPF | Tags: .NET, C#, Desktop Bridge, MSIX, UWP, WPF 3 Comments
An example of how to handle Uniform Resource Identifier (URI) protocol and file extension activation in a packaged WPF application.
Implicit Data Templates in UWPPosted: March 25, 2017 Filed under: C#, UWP, XAML | Tags: C#, UWP, XAML 1 Comment
In WPF the use of implicit data templates without an
x:Key makes it easy to associate a template with a particular type of object. You just set the
DataType property of the
DataTemplate to the corresponding type and the template is then applied automatically to all instances of that particular type.
The Universal Windows Platform (UWP) however has no concept of implicit data templates. Each
DataTemplate that you define in a UWP app must have an
x:Key attribute and it must be set to a
Implementing global hot keys in WPFPosted: March 31, 2015 Filed under: .NET, C#, WPF | Tags: .NET, C#, WPF 7 Comments
If you want your WPF application to be able to detect and handle key presses even when it is not currently activated or focused on the screen you could implement what is known as global hot keys in Windows.
A global, or system-wide, hot key is a key or a combination of keys that is associated with a particular window, which will receive messages whenever the user presses this key or key combination from anywhere in the system.
Enumerating collections that change in C#Posted: February 28, 2015 Filed under: .NET, C# | Tags: .NET, C# 3 Comments
If you try you remove an item from an IEnumerable while enumerating it using a foreach loop in C# you will get an InvalidOperationException saying that “Collection was modified; enumeration operation may not execute”.
Generic type parameters and dynamic types in C#Posted: October 31, 2014 Filed under: .NET, C# | Tags: .NET, C# Leave a comment
There may be times when you need to use some type in your application that is not known until runtime. This post will explain what you need to do in order to be able to use such a dynamically loaded type from a dynamically loaded assembly as a generic type parameter when you create an instance of some generic class in your application.
Adding right-aligned row numbers to a DataGridRowHeader in WPFPosted: August 18, 2014 Filed under: WPF | Tags: C#, WPF, XAML 3 Comments
This post provides an example of how you can right-align or centre the text in a DataGridRowHeader in a DataGrid in WPF using Visual Studio 2012 or later. It also explains how you can display the correct row numbers in the DataGridRowHeader and automatically update these as you are adding or removing items to and from the DataGrid’s ItemsSource collection dynamically.
Tabbing between items in a ListBox in WPFPosted: August 13, 2014 Filed under: WPF, XAML | Tags: C#, MVVM, WPF, XAML Leave a comment
This post explains what XAML changes you need to make in order to be able to navigate between elements that are the defined in the ItemsTemplate of a WPF ListBox using the TAB key on the keyboard.
Merging cells in a WPF ListViewPosted: May 31, 2014 Filed under: WPF | Tags: .NET, C#, MVVM, WPF, XAML 7 Comments
This post provides an example of how you can merge cells that contain the same value in a ListView in WPF and make it look like the cell spans several rows as shown in the rightmost picture below.
Using behaviours to bind to read-only properties in MVVMPosted: January 30, 2014 Filed under: MVVM, WPF | Tags: C#, MVVM, WPF 6 Comments
If you have ever tried to for example bind the SelectedItem property of a TreeView control or the SelectedDates property of a Calendar control to some source property of a view model, you know that these properties are read-only, i.e. they don’t have a publicly accessible setter.
This post provides two different code samples on how you can use something called attached behaviours to be able to synchronize a source property of a view model class with a custom dependency property that acts as replacement for an existing read-only dependency property of some user interface control.
How to export data from a DataGrid in WPFPosted: September 29, 2013 Filed under: WPF | Tags: .NET, C#, WPF, XAML 1 Comment
The DataGrid control in WPF provides a flexible way to display, sort, group and filter tabular data. A common requirement is the ability to export this data to some physical file that can be imported into Microsoft Excel or some similar software for further processing.
This post provides an example of how you could create a .csv file out of a data-bound collection of objects of any type by using reflection and extending the functionality of the System.Windows.Controls.DataGrid control by implementing an extension method.
Cascading ComboBoxes in WPF using MVVMPosted: June 17, 2013 Filed under: MVVM, WPF | Tags: .NET, C#, MVVM, WPF, XAML 6 Comments
When a user is selecting an item from a cascading ComboBox, another ComboBox gets automatically populated with items based on the selection in the first one. This post is about how you can implement this behaviour in a WPF application using the MVVM (Model-View-ViewModel) pattern.
Implementing a generic data access layer using Entity FrameworkPosted: May 30, 2013 Filed under: Entity Framework, N-tier | Tags: .NET, C#, Entity Framework, N-tier 159 Comments
This post is about how you can develop a generic data access layer (DAL) with full CRUD (Create, Read, Update and Delete) support using Entity Framework 5 with plain old CLR objects (POCOs) and short-lived contexts in a disconnected and stateless N-tier application.
Entity Framework (EF) is Microsoft’s recommended data access technology when building new .NET applications. It is an object-relational mapping framework (ORM) that enables developers to work with relational data using domain-specific objects without having to write code to access data from a database.
Implement a MVVM loading dialog in WPFPosted: April 30, 2013 Filed under: MVVM, Prism, WPF | Tags: .NET, C#, CancellationToken, MVVM, Prism, TPL, WPF, XAML Leave a comment
Continuing from my last post about how to display dialogs to the user in a MVVM WPF application using Prism without breaking the pattern, this one is about how you can extend the built-in functionality to implement a loading dialog to be shown to the user while running a background operation.
Implement a confirmation dialog in WPF using MVVM and PrismPosted: April 20, 2013 Filed under: MVVM, Prism, WPF | Tags: .NET, C#, MVVM, Prism, WPF 12 Comments
If you are serious about implementing the MVVM pattern in your UI applications you should be well aware of the fact that any call you make to System.Windows.MessageBox.Show from your view models violates this pattern and the separation of concerns that exists between the application’s logic and its presentation.
By honoring the MVVM design pattern and its principles your application is likely to require less effort when you make changes in one area or another as the presentation layer (the view), the presentation logic layer (the view model) and the business model layer (model) are decoupled from each other. Other benefits include testability and the fact that designers and developers can work concurrently and independently.
Custom authorization in WPFPosted: March 24, 2013 Filed under: .NET, C#, Security, WPF | Tags: .NET, C#, IIdentity, IPrincipal, MVVM, WPF, XAML 51 Comments
This post provides a code sample on how to implement your own custom authentication and authorization in a WPF application by implementing classes that derive from the IIdentity and IPrincipal interfaces and overriding the application thread’s default identity.
How to create a custom window in WPFPosted: March 16, 2013 Filed under: Custom Controls, WPF | Tags: .NET, C#, Custom Controls, Visual Studio, WPF 90 Comments
This introductory post will provide a walkthrough on how to create your own custom looking window control with resize, drag, minimize, restore and close functionality and how to use it in your WPF applications.