ReSharper Tip – Creating a “Surround With” template

Pieter van der Westhuizen, a professional freelance web & mobile developer and founder of Coalition Software.
Search for a command to run...

Pieter van der Westhuizen, a professional freelance web & mobile developer and founder of Coalition Software.
A recent requirement came up for configurable dynamic forms in a mobile application. There are a few dynamic form packages for Flutter, but I wanted a bit more control over the schema and behavior of the form. Here follows my attempt at creating dyna...

If you've ever written a mobile app with Flutter that integrates with an API, then you'll know that there are a lot of model objects that get passed between the app and the API. JSON Serialization in Flutter can also take a fair amount of boilerplate...

Back in May 2020, Microsoft announced a new feature for Azure Blob Storage called Blob Index. Essentially, this enables you to add key/value tags to your Blob objects and be able to query said Blob objects without having to use a separate service lik...

In my last post, "Using AWS Cognito with Xamarin Forms", I showed how to authenticate with Amazon Cognito using Xamarin Forms and the Xamarin.Essentials Web Authenticator. In this post, we'll go through the process of using the AWS Cognito Hosted UI ...

In this post, I'll show you how to quickly and easily set up user authentication for your Xamarin Forms app using Amazon Cognito. AWS Cognito is a user identity management solution by Amazon. It is a really easy way to add authentication to your appl...

I’m not going to deny it. I’m a fan of ReSharper. One of it’s many feature is the ability to create your own code templates.
Whilst busy with a Xamarin Forms project. I needed a quick way to surround blocks of XAML code with a region.
Yes, you can add regions to XAML code. To give you an idea of what I mean, here is a small example of a region in XAML:
So, let’s quickly go through the steps of creating a ReSharper template to surround any piece of XAML code with the correct markup for a region.
Add the following code to the template editor window:
Set the following properties for the template:
Shortcut: region
Mnemonic: 2
Make sure the Reformat and Surrounding checkbox and radio button is selected.
The final result should look like the following:

Now, when you select a piece of XAML code, you should see region inside the ReSharper “Surround with” context menu:

The result will be the code nicely wrapped inside a region, which can be collapsed to help with readability:

Thank you for reading. Until next time, keep coding!