Total Articles: 57

Through this article series, you've created several .NET MAUI pages, performed navigation, used data binding, and worked with the MVVM and DI design patterns. As you created your view models, you've set information and exception message properties. In this article, you'll build reusable components to display information, error, and validation messages on your pages. To validate user input, you're going to use data annotation attributes such as [Required] and [Range]. With just a little generic code, you can add validation to your .NET MAUI applications and display the error messages from these data annotation attributes. Sometimes you require a pop-up dialog to ask the user a question, get a little piece of data, or maybe just provide some information to the user. There are a few different dialogs you can use in .NET MAUI and you'll start this article by exploring these.

In this article series, you've created several .NET MAUI pages, created a top-level menu system, and programmatically navigated between pages. Using data binding greatly reduces the amount of code you need to write. Using the MVVM and DI design patterns helps you create applications that are reusable, maintainable, and testable. In this article, you'll display lists of data and navigate from a list item to the detail page for that item. .NET MAUI provides ListView, CollectionView, and CarouselView controls for displaying lists. Each list control is illustrated, and you're provided with guidance on what each control is best at displaying.

Up to this point in this article series on .NET MAUI, you created a set of typical business application input pages and learned about the many different controls you can use for data input. Data binding is a great feature of .NET MAUI to help you eliminate C# code in your applications. In this article, you'll learn the Model-View-View-Model (MVVM) and Dependency Injection (DI) design patterns to create reusable, maintainable, and testable applications. You'll learn to eliminate code in your code-behind by taking advantage of Commanding. You'll also learn how to apply Commanding while keeping your various components reusable across other types of applications. Finally, you'll learn how to keep your MauiProgram class maintainable by employing extension methods.

In this article, you'll continue to use more data entry controls and learn to perform data binding between controls. You're going to create a class with properties that you can bind to controls on a page as well. When you change the values of properties in a class, you need to raise a PropertyChanged event so the UI can update those controls that are bound to the properties. You're going to create a base class that helps you raise that event any time the property values change.

In this article, you'll learn to apply styles so all pages in your application look consistent. You'll create several pages and learn how to use the built-in navigation to move from one page to another. Using a ContentView control, you'll create a header with data bindings that you can reuse on all pages in your application. Finally, you'll add a border and a scroll viewer around all your controls.

Unlock the true potential of cross-platform development with eXtensible Application Markup Language (XAML) and .NET MAUI (Multi-platform App UI). Say goodbye to the frustration of writing code for each platform separately. With .NET MAUI, you can develop powerful business applications that run seamlessly on Windows, Android, Mac, and iPhone devices. In this series of articles, I'll guide you through the process of building a complete business application from scratch, step by step.

JavaScript Object Notation (JSON) is a great way of storing configuration settings for a .NET application. JSON is also an efficient method to transfer data from one machine to another. JSON is easy to create, is human readable, and is easy for programming languages to parse and generate. This text-based format for representing data is language agnostic and thus easy to use in C#, JavaScript, Python, and almost any programming language existing today. In this article, you're going to learn multiple methods of creating and manipulating JSON documents in .NET 8. In addition, you'll learn how to serialize and deserialize C# objects to and from JSON.

In this article, you're going to learn the many ways to serialize and deserialize C# objects to and from memory and disk. Along the way, you're going to create some classes with extension methods to simplify the serialization process.

In this article you are going to learn how to read and write XML files using C# and .NET Core. There are a few minor differences from the .NET Framework classes you used before. The .NET Core XML processing has been greatly optimized and processes XML files much faster than the .NET Framework. In this article you learn to create XML document in memory, save and load XML files from disk. You also see how to use LINQ to XML for processing XML nodes including sorting, filtering, and aggregation.

In this article you learn how to use the GetSchema() method on the DbConnection class to retrieve tables, views, columns, index, stored procedures and more from any database system. This method is implemented by each data provider to retrieve schema information in a generic fashion. What do you do with this information? You can present column names to your user to let them select columns to filter on for a report. You can use it to build your own code generator. You can even use it to create a SQL comparison tool. Read and follow along with this article to see how easy it is to use GetShema() to accomplish these various tasks.

Data annotations are not only for use in ASP.NET web applications. Any type of .NET application can use data annotations for validating data. It only takes about 10 lines of code to programmatically validate data annotations attached to entity classes. There are many built-in data annotations supplied by Microsoft that can validate your data quickly and it's easy to create your own data annotation attributes to apply to your entity classes. If you have some very specific validation needs, you may implement the IValidatableObject interface for your entity classes. If you're developing multilingual applications, you can even move your error messages into resources and specify the name of those resources on each of your attributes.

In the last two articles (Simplifying ADO.NET Code in .NET Core: Part 1 and Part 2), you learned how to retrieve data using a set of wrapper classes around ADO.NET. The code you wrote was about the same lines of code you might write when using the Entity Framework. In this article, you're going to build the appropriate methods to modify data in a table, perform transactions, validate data using data annotations, and add exception handling.

In the last article (Simplifying ADO.NET Code in .NET Core: Part 1), you wrote code to simplify ADO.NET and map columns to properties in a class just like ORMs such as the Entity Framework do. You learned to use reflection to make creating a collection of entity objects from a data reader and take advantage of attributes such as [Column] and [NotMapped]. In this article, you're going to refactor the code further to make it even more generic. In addition, you'll learn to get data from a view, get a scalar value, handle multiple result sets, and call stored procedures.

When developers think of how to access data, many use the Entity Framework (EF), Dapper, NHibernate, or some other object-relational mapper (ORM). Each of these ORMs use ADO.NET to submit their SQL queries to the backend database. So, why do many developers use ORMs instead of just using ADO.NET directly? Simply put, ORMs allow you to write less code. If each of these ORMs are simply wrappers around ADO.NET, can't you write your own wrapper to cut down the amount of code you need to write? Absolutely! This series of articles shows you how to create a set of reusable wrapper classes to make it simpler to work with ADO.NET in .NET Core.

It's very easy to get started using Minimal Web APIs in .NET Core, but as the number of routes grows , your Program.cs file can easily become overwhelming to maintain. Instead of keeping all your app.Map*() methods in the Program.cs file, you should create a Router class to separate your groups of app.Map() methods into. For example, if you have a set of CRUD routes for working with products and another set for working with customers, create a ProductRouter class and a CustomerRouter class. In this article, you're going to see how to move each group of Web APIs into their own router class to provide a much more consistent and maintainable way to create Minimal Web API calls.

This article continues my series on how to enhance the user experience (UX) of your MVC applications, and how to make them faster. In the first three articles, entitled Enhance Your MVC Applications Using JavaScript and jQuery: Part 1, 2, and 3, you learned about the starting MVC application that was coded using all server-side C#. You then added JavaScript and jQuery to avoid post-backs and enhance the UX in various ways. If you haven't already read these articles, I highly recommend that you read them to learn about the application you're enhancing in this series of articles. In this article, you continue learning how to add more Ajax to your MVC application to further speed up your Web pages.

In this article I am continuing my series on how to enhance the user experience (UX) of your MVC applications, and how to make them faster. In this article you are going to build Web API calls you can call from the application to avoid post-backs. You are going to add calls to add, update and delete shopping cart information. In addition, you are going to learn to work with dependent drop-down lists to also avoid post-backs. Finally, you learn to use jQuery auto-complete instead of a drop-down list to provide more flexibility to your user.

In this article, I'm continuing my series on how to enhance the user experience (UX) of your MVC applications, and how to make them faster. You're going to continue to add additional client-side code to the MVC application to further enhance the UX as you work your way through this article. You'll learn to expand search areas after the user performs a search, hide certain HTML elements when printing a Web page, and create custom jQuery validation rules to enforce business rules on the client-side.

In this first of a multi-part article series, I'm presenting an MVC application written with all server-side code to which you are going to add client-side code to make the user experience better and to make the application more efficient. Some of the things you'll learn in this article display a 'Please Wait' message for any long operations, complete with a spinner from Font Awesome. You're going to disable all buttons and links, and gray the background, while long operations take place so the user can't accidentally click on something else. You're going to learn how to use Bootstrap events to toggle collapsible areas so only one is open at a time. In addition, you'll learn to use the setInterval() function to display a countdown until the user's shopping cart is cleared.

In this article you learn to use the Fetch API which is a promise-based wrapper around the XMLHttpRequest object. As you will see, the Fetch API makes using the XMLHttpRequest object easier to use in some ways but does have some drawbacks where error handling is concerned. To make working with the Fetch API a little easier a set of IIFE's (closures) are created in this article. Using a closure makes your code easier to read, debug and reuse. You do not need to have read the previous articles to read this one. However, the .NET Core Web API project is created from scratch in the first article, so reference that article if you want to learn to build a CRUD Web API using .NET Core.

This article is going to continue with where you left off and finish creating a page that allows you to display a list of product data, add, edit, and delete products. If you use JavaScript, jQuery, Angular, React or almost any front-end framework, you most likely use Ajax to get and modify data from a server. Most of those front-end frameworks have their own wrapper around the XMLHttpRequest object. What you are learning in this series of articles is how to use this object natively. I am always a big fan of understanding what goes on under the hood as I believe it makes me a better programmer. If you are reading this article, and the last one, then you believe the same. So, let's create a CRUD page using JavaScript and the XMLHttpRequest object.

This is the first in a series of articles where you'll learn to use Ajax and REST APIs to create efficient front-end applications. In this article, you create a .NET Core Web server to service Web API calls coming from any Ajax front-end. You also learn to create an MVC Web application and a Node server to serve up Web pages from which you make Ajax calls to the .NET Core Web server. In future articles, I'll show you how to use the XMLHttpRequest object, the Fetch API, and jQuery to communicate efficiently with a .NET Core Web API project.

Working with stored procedures using the Entity Framework (EF) is a challenge because depending on what the stored procedure does determines how you call it using EF. This inconsistency, along with the names of the methods you call to submit a stored procedure change from one version of EF to the next can lead to much frustration for developers. This article will not solve these issues, but it will show you how to make calls to stored procedures using the version of Entity Framework in .NET Core.x. You are going to learn how to retrieve data from a stored procedure, how to pass parameters, return a scalar value, modify data, and handle multiple result sets.

In this final part of this article series, you build a product detail page to add and edit product data. You add a delete button on the list page to remove a product from the database. You learn to validate product data and display validation messages to the user. Finally, you learn to cancel out of an add or edit page, bypassing validation and returning to the product list page.

In this article, you're going to add on to the sample from the last article to sort the database when the user clicks on any of the column headers in the HTML table. You're going to learn how to add a pager to your HTML table so only a specified number of rows are displayed on the page. Finally, you learn to cache the product data in the Session object to improve performance.

This article presents how to use the Model-View-View-Model (MVVM) design pattern in MVC Core applications. The MVVM approach has long been used in WPF applications but hasn't been as prevalent in MVC or MVC Core applications. This article illustrates how using MVVM in MVC makes your applications even more reusable, testable, and maintainable. You're going to be guided step-by-step building an MVC Core application using the Entity Framework (EF) and a view model class to display and search for product data.

A WPF Security System

Published: 2/1/2020

Unlike MVC or Web Forms, when using WPF, you don't get a pre-built security system. Thus, you need to come up with your own method of securing controls on WPF screens, such as the one shown in Figure 1. There are a few different methods to accomplish this goal. For example, you can create different properties in your View model to make controls invisible or disabled based on a user's role. The problem with this approach is that if you need to secure more controls, you need to change the code and then redistribute your WPF application to your users. In this article, I'm going to take a data-driven approach to security so you can make changes in a database table and have your WPF application's security update without having to make code changes.

In the previous articles in this series on building a WPF business application (check www.CODEMag.com for the others), you created a new WPF business application using a pre-existing architecture. You added code to display a message while loading resources in the background. You also learned how to load and close user controls on a main window. You built a login screen, a user feedback screen, and a user maintenance screen to display a list of users, and the detail for a single user. In this article, you're going to finish this user maintenance screen by learning to manage button state, and to add, edit, and delete users.

In part 3 of this series, you'll build a user feedback screen to allow a user to submit feedback about the application. You build a view model and bind an Entity Framework entity class to the screen. The entity class contains data annotations and you learn to display validation messages from any data annotations that fail validation. You also start learning how to build a design pattern for standard add, edit, and delete screens. You build a user list control and a user detail control to display all users in a table, and the detail for each one you click on.

In Part 2 of this series, you're going to display a status message by sending a message from a View Model class to the main window. You're going to reuse the splash screen area that you built in Part 1 to display informational messages. A timer will be used to have these informational messages disappear after a specific amount of time. Finally, you'll create a WPF login screen with an image, a title area, and input fields for a user name and password. The user name and password data is validated and appropriate validation messages are displayed to the user.

When building any kind of application, it's important to start with a good architecture, a set of reusable helper classes, and design patterns. In this first of a multi-part series of articles, you'll learn to use a message broker to eliminate strong coupling between classes. You'll see how to display status and informational messages to the user while resources are loading. Instead of having a ton of open windows, you'll learn to load user controls onto a single window and how to aggregate controls and build large screens.

Using user controls for each of your screens is a great way to build WPF applications. Instead of having multiple windows pop-up on a user's screen, each user control can be loaded onto one main window. You do miss out on having the Minimize, Maximize, and Close buttons that a WPF window provides with this method. That's an easy situation to rectify and is the subject of this article.

It seems that more programmers are switching to C# from Visual Basic (VB) than ever before. As we all see when searching the Web, there are more samples in C# than there are in VB. Visual Basic is a perfectly good language for creating .NET applications, but it's just not the cool kid down the block anymore. If you currently have VB applications, and your current programmer(s) quit, you're going to be hard-pressed to replace them. Programmers don't want to keep working in what are viewed as legacy technologies. Right or wrong as that might be, you can't fight the trend.

It seems that more programmers are switching to C# from Visual Basic (VB) than ever before. As we all see when searching the Web, there are more samples in C# than there are in VB. Visual Basic is a perfectly good language for creating .NET applications, but it's just not the cool kid down the block anymore. If you currently have VB applications, and your current programmer(s) quit, you're going to be hard-pressed to replace them. Programmers don't want to keep working in what are viewed as legacy technologies. Right or wrong as that might be, you can't fight the trend.

Every developer needs to test their own code or have it tested by someone else. Many developers aren't great at testing their own work. The main reason is that we tend to test only the happy path" through the functionality that we wrote. We often avoid testing the boundaries of our code, such as invalid inputs, exceptions that might occur, etc. One way to become a better tester is to start writing unit tests. Although it takes more time up-front to write unit tests, it saves a ton of time if you have to regress test changes to existing features.

In the last two articles about CRUD and HTML (CODE Magazine, November/December 2015 and January/February 2016), you created a product information page to display a list of product data returned from a Web API. In addition, you built functionality to add, update, and delete products using the same Web API controller. In those two articles, there was a very basic exception handler function named handleException. This function displays error information returned from the API in an alert dialog on your page, as shown in Figure 1.

When a user clicks on a button or link on a Web page, there can be a delay between posting to the server and the next action that happens on the screen. The problem with this delay is that the user may not know that they already clicked on the button and they might t hit the button again. It's important to give immediate feedback to the user so they know that the application is doing something.

Use HTML 5 and jQuery in WebForms

Published: 12/1/2014

Many businesses have invested thousands of man-hours into ASP.NET Web Forms. These same businesses don't have time to rewrite their systems using the latest Web technologies, such as MVC. However, with just a little reworking of your Web Forms, you can still get all the advantages of modern Web techniques, such as HTML 5, CSS 3, Bootstrap, and jQuery. Lately, I've been assisting many clients as they upgrade their Web Forms applications to take advantage of Bootstrap, jQuery, JavaScript, Friendly URLs, and many other modern Web application techniques.

It seems like everywhere you read, everyone is talking about using ASP.NET MVC to create mobile Web applications. But what about programmers still working in Web Forms? We want our projects done using the latest techniques, we want to build mobile Web apps, and we want to use jQuery and Bootstrap, too.

Tips and Tricks for Flexible Code

Published: 6/1/2014

The .NET Framework is huge. There's often more than one way to accomplish the same programming task, and knowing which way to go can sometimes make the difference between code that is slow or fast, flexible or rigid, and either maintainable or a maintenance nightmare. In this article, you will learn several tips and tricks for developing code that is flexible, extensible, maintainable, and testable. Some techniques in this article may be familiar to you, while others you may not have thought of.

There are many examples of using the Windows Presentation Foundataion (WPF) Tree View that you can find on the Web, however, most of them only show you how to go to two levels. What if you have more than two levels? This is where it's vital to understand exactly how the Hierarchical Data Templates work. In this article, I'm going to break down how these templates work, so you can really understand what's going on underneath the hood.

Using Active Directory in .NET

Published: 12/1/2013

Sometimes your .NET applications need to interact with Microsoft Active Directory (AD) to authenticate users, get a list of users, retrieve groups, or determine which users are within which AD groups. There are a few different approaches you can use to retrieve information from your AD database within your domain.

I have a client that has a few Windows Services and some EXEs that run on a computer to perform various business functions. Every once in a while, the processes fail and need to be restarted. I helped the client write a Windows Service to monitor their running processes and ensure that they are up and running and to notify them and to attempt to restart those processes. As part of this process, I had to write a class to get a list of all of the processes running on the current computer or on another computer on their network.

If you are like many developers, you are using Windows Communication Foundation (WCF) to provide services to Windows Forms, WPF, Silverlight, ASP.NET and possibly Windows 8 Store applications. Now your boss is asking you to develop some mobile applications using HTML 5 and jQuery. You know you can reuse many of your WCF services, but you are having trouble calling them from jQuery without breaking your existing applications. In this article, I will walk you through the steps for taking a sample WCF service from working just for .NET applications to working with jQuery as well. Don't worry, your existing applications will still work with the changes you are going to make.

Almost every programmer knows (unless you have been living under a rock for the last five years or so) that you should be using classes for all of your programming. You should also be using collections of objects instead of using a Data Reader, a DataSet, or a DataTable in your applications. The reasons for using collections are many and are explored in this article.

In Part 1 of this article you learned how to create a Windows 8 look and feel for your WPF applications. In Part 2 of this article you learned to create a few of the user controls that went into making the shell application. In this final article in this series, you will learn how to create the last few user controls that I used to create the Windows 8 Shell application. In this article, you will learn to put together a WPF Image button, an Image button with text and finally the main Tiles used for the primary navigation system.

In part 1 of this article, you learned how to create a Windows 8 look and feel for your WPF applications. You were shown a high-level overview of the various components that made up the shell for navigating. In part 2 of this article you will learn to create a WPF Button user control, a Message Box you can style, and a simple Message Broker System. All of these components are used to create the 'Windows 8 Style' WPF shell you learned about in part 1.

Many people will not be able to upgrade to Windows 8 right away for various reasons. However, there is nothing to stop you from designing your WPF applications to have a similar look and feel. In this article I will show you how to create a Windows 8 style shell (Figure 1) for hosting 'Tiles' that you can use to launch features of your application. The first part of this article will discuss how to create the main window, use the tiles to launch applications and how to navigate around the shell. In the second part of this article you will learn about the different user controls used to build this application.

LINQ to XML Instead of a Database

Published: 10/1/2012

When people think of having to store data for their applications, a database such as SQL Server immediately comes to mind. However, XML files are very handy for storing data without the overhead of a database. Using XML files to cache often-used, but seldom changed data such as US state codes, employee types and other validation tables can avoid network roundtrips and speed up your application. In addition, XML files are great for off-line applications where a user needs to add, edit and delete data when they can't connect to a database.

Getting Rid of Your Code Behind

Published: 8/1/2012

You know you should be moving code out from behind your forms, windows and web pages and into stand-alone classes. Everyone preaches that this is what to do, everyone shows you examples of ViewModel classes, but no one really shows you a real-world example of how to get rid of the code behind.

MVVM Made Simple

Published: 12/1/2010

Have you found that you can understand the basics of data binding in WPF and Silverlight, but when you start to read about Model-View-View-Model (MVVM) you find that you have been dropped off a cliff? Have you looked at some of the XAML frameworks like PRISM only to find that it is just way too complicated for what you need? If this sounds familiar, then don't worry, you are not alone. Many great programmers struggle with this every day. In my humble opinion, I say don't try to implement a pure MVVM model. Just keep it simple! Many times the simplest approach is the best.

In a WPF application I am building right now, I have a need to create different shapes and center text within those shapes. The shapes I need are rectangles, circles, ellipses and triangles. The problem is WPF shapes are not containers so you cannot add any text inside of them, but WPF is flexible enough that there are often several ways to work around this. In this article, I will show you a few different methods of centering text in each of these shapes.

Why Use WPF?

Published: 12/1/2009

If you have not taken a look at Windows Presentation Foundation (WPF) yet, you really should. WPF is a great desktop development platform. Granted, all of the tools are not yet in place, but Microsoft is pouring millions of dollars into developing WPF tools. Microsoft now considers Windows Forms a legacy technology and they won't update it within

The Provider Model

Published: 2/1/2009

In this article you will learn how to isolate yourself from change by taking advantage of the Provider Model. Designing your applications using the Provider Model will allow you to swap components out at runtime, thus allowing you to upgrade them easily.

ASP.NET Whidbey adds a huge number of productivity features and enhancements. Although it's still early in the development process, Paul and Ken dig in and start playing with some of the new features, passing along what they've found.

Good exception handling should be put into an application from the very beginning. The Microsoft Exception Management Application Block (EAAB) will allow you to write one line of code in all of your Catch blocks and this one line of code can be configured to call multiple classes to log errors in any way you see fit. The best part is you do not need to recompile your application; you simply have to provide a new DLL that contains these new exception classes.

Most of you are probably aware that the web.config file in an ASP.NET project controls the behavior of your Web site. If you make a change to one of the built-in settings in this file, ASP.NET automatically detects those changes and applies them immediately. Wouldn't it be nice if you could have your own settings in this file applied immediately as well? In this article you will learn how to do just that. You will also learn the difference between the Application object and creating your own Configuration class.