<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mike Grant</title>
    <description>The latest articles on DEV Community by Mike Grant (@mikegrant).</description>
    <link>https://dev.to/mikegrant</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F344596%2F6db465de-b073-44a3-b0a2-9b62af47ce47.png</url>
      <title>DEV Community: Mike Grant</title>
      <link>https://dev.to/mikegrant</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mikegrant"/>
    <language>en</language>
    <item>
      <title>.NET MAUI - Auto Scaling App Icons &amp; App Image Resources</title>
      <dc:creator>Mike Grant</dc:creator>
      <pubDate>Mon, 31 Jan 2022 00:00:00 +0000</pubDate>
      <link>https://dev.to/mikegrant/net-maui-auto-scaling-app-icons-app-image-resources-1fnh</link>
      <guid>https://dev.to/mikegrant/net-maui-auto-scaling-app-icons-app-image-resources-1fnh</guid>
      <description>&lt;p&gt;Managing images in your .NET MAUI application is a lot easier than with Xamarin.Forms. .NET MAUI removes the need to scale and resize your images for each platform and screen resolution. Better than that, it saves you having to remember that website that generates it all for you. Add your images to your project, ensure the build actions are configured, and boom! .NET MAUI will handle the process for you at build time.&lt;/p&gt;

&lt;p&gt;If you’re interested in how .NET MAUI is resizing the images at build time, you can view the source of the tool (ResizetizerNT) over at &lt;a href="https://github.com/redth/ResizetizerNT"&gt;GitHub&lt;/a&gt;. During the build process, ResizetizerNT processes the shared resources and resizes them to the appropriate resolution for each platform and screen size. It’s important to note that whilst &lt;code&gt;.svg&lt;/code&gt; files are the recommended and preferred format, it will also handle &lt;code&gt;.png&lt;/code&gt; and bitmaps.&lt;/p&gt;

&lt;h2&gt;
  
  
  App Icons
&lt;/h2&gt;

&lt;p&gt;To add your app icon to your project, drag the image into the &lt;code&gt;Resources\&lt;/code&gt; folder within your project. Then by changing the &lt;code&gt;Build Action&lt;/code&gt; of the image to &lt;code&gt;MauiIcon&lt;/code&gt; in the &lt;code&gt;Properties&lt;/code&gt; window, this will let .NET MAUI know to configure each platform to use this image as the icon, as well as resizing the icon at build time.&lt;/p&gt;

&lt;p&gt;It’s worth being aware that the &lt;code&gt;.svg&lt;/code&gt; file format is recommended for app icons with MAUI compared to &lt;code&gt;.png&lt;/code&gt; files which are regularly used when developing a Xamarin.Forms application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--E_CnzAPj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mikegrant.org.uk/assets/2022-01-31/maui-app-icon.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--E_CnzAPj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mikegrant.org.uk/assets/2022-01-31/maui-app-icon.webp" alt="App Icon Properties" width="362" height="708"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also configure this manually by adding the following to your project file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;MauiIcon Include="Resources\Images\appicon.svg"&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can find all of the images created as a result of the resizer by running a build, navigating to the &lt;code&gt;obj&lt;/code&gt; folder, and browsing into one of the builds (e.g. &lt;code&gt;net6.0-android&lt;/code&gt;). For example with Android, go into the build output and select&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CcIBsyKG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mikegrant.org.uk/assets/2022-01-31/maui-resizer-output.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CcIBsyKG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mikegrant.org.uk/assets/2022-01-31/maui-resizer-output.webp" alt="Folder containing the resized image" width="880" height="309"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  App Images
&lt;/h2&gt;

&lt;p&gt;You can also resize images that you want to show in the application in a similar way to how app icons are handled. Again, these images will be resized at build time.&lt;/p&gt;

&lt;p&gt;By default, your project will be set up to automatically resize any images that are placed in the &lt;code&gt;Resources\Images&lt;/code&gt; folder. If you wish to use a different folder structure for your project, you can edit this line in your .csproj file and change it to point to a location that suits you.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;MauiImage Include="Resources\Images\*"&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also add specific images outside of this file by changing the &lt;code&gt;Build Action&lt;/code&gt; to &lt;code&gt;MauiImage&lt;/code&gt; or even add extra folder locations by adding the following to your &lt;code&gt;.csproj&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;MauiImage Include="YourFolder\ExtraImages\*"&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YYGP6UHF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mikegrant.org.uk/assets/2022-01-31/maui-image.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YYGP6UHF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mikegrant.org.uk/assets/2022-01-31/maui-image.webp" alt="Changing Build Action of an Image so that it will be resized" width="354" height="292"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;.NET MAUI is still a preview release. Whilst this blog post is accurate for .NET MAUI Preview 12, this does not guarantee that it will be correct when .NET MAUI is officially released.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>maui</category>
      <category>dotnet</category>
    </item>
    <item>
      <title>Controlling Streaming Services with Alexa - Part 1</title>
      <dc:creator>Mike Grant</dc:creator>
      <pubDate>Thu, 12 Aug 2021 23:00:00 +0000</pubDate>
      <link>https://dev.to/mikegrant/controlling-streaming-services-with-alexa-part-1-g3c</link>
      <guid>https://dev.to/mikegrant/controlling-streaming-services-with-alexa-part-1-g3c</guid>
      <description>&lt;p&gt;One of the biggest problems that I’ve found with the sheer amount of streaming services is which one has what? Sometimes I’ll miss great content on Amazon Prime because I get frustrated browsing their app on my TV, or I want to watch a certain film, can’t find it on Netflix, and just assume that it’s not available to be streamed from anywhere. Why can’t I just ask my voice assistant (Alexa) to play a TV show or film and it plays on my TV irrespective of which streaming service it is on?&lt;/p&gt;

&lt;p&gt;I currently use Alexa to control a lot of things in my house through Home Assistant and a custom skill for some of the more complicated tasks, so I set about creating a custom Alexa skill that will allow me to play content from the streaming services that I’ve subscribed to, on my TV. (Think “Okay Google, play Stranger Things on TV”)&lt;/p&gt;

&lt;h2&gt;
  
  
  What do I need?
&lt;/h2&gt;

&lt;p&gt;Before starting working on this project, I sat down and thought about what I needed to make this work, and the list was surprisingly small.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Control of my TVs (via ADB)&lt;/li&gt;
&lt;li&gt;Intent information for each streaming service&lt;/li&gt;
&lt;li&gt;Data about what content is available on each service&lt;/li&gt;
&lt;li&gt;Alexa Skill&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Controlling the TV
&lt;/h2&gt;

&lt;p&gt;Before we can play anything on the TV, we need to find a way to open the content that we want on the TV. As I have Android based devices, this is relatively easy for me. I can use ADB and &lt;a href="https://developer.android.com/guide/components/intents-filters"&gt;intents&lt;/a&gt;. As part of my home automation system, I already have an ADB server running in a container, which is connected to my TVs. This saves me having to open and close connections to each of my TVs everytime I want to control them.&lt;/p&gt;

&lt;p&gt;To open content on the TV, I’ve used the intent URL scheme so that everything is uniform and easier to work with. After trawling the internet I compiled this list of intents for the three main streaming services that I use.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Netflix - intent://www.netflix.com/watch/CONTENTID#Intent;launchFlags=0x00800000;scheme=https;package=com.netflix.ninja;S.source=30;end Amazon Prime - intent://com.amazon.tv.launcher/detail?provider=aiv&amp;amp;providerId=ASIN#Intent;package=com.amazon.tv.launcher;scheme=amzn;end Disney+ - intent://disneyplus.com/VIDEOID#Intent;launchFlags=0x00800000;scheme=https;package=com.disney.disneyplus;end 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can validate these intents are working by using an adb shell that is connected to one of the TVs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;am start intent://www.netflix.com/watch/CONTENTID#Intent;launchFlags=0x00800000;scheme=https;package=com.netflix.ninja;S.source=30;end 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will start Netflix on the device and the content will beging playing within a couple of seconds.&lt;/p&gt;

&lt;h2&gt;
  
  
  Playing content on the TV
&lt;/h2&gt;

&lt;p&gt;Now that we can control our TV using ADB, we can build upon this by creating a simple script that takes a Netflix video link and sends the command to my TV via the ADB server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var adb = require('@devicefarmer/adbkit') var client = adb.createClient({ host: '127.0.0.1', port: '5037' }) contentIntent = 'intent://www.netflix.com/watch/80126025#Intent;launchFlags=0x00800000;scheme=https;package=com.netflix.ninja;S.source=30;end' client.shell('192.168.1.1', `am start "${contentIntent}"`).then(function (response) { console.log(response) }).catch(function (err) { console.log(err); }) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Running this script will open Star Trek: Discovery on the TV and we’ve validated that the idea will work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Seeing it in action
&lt;/h2&gt;



&lt;p&gt;Check back soon for more details on this project.&lt;/p&gt;

</description>
      <category>homeautomation</category>
      <category>smarthome</category>
      <category>voiceassistant</category>
    </item>
    <item>
      <title>Xamarin Let’s Build - Biometric Support</title>
      <dc:creator>Mike Grant</dc:creator>
      <pubDate>Mon, 08 Mar 2021 00:00:00 +0000</pubDate>
      <link>https://dev.to/mikegrant/xamarin-let-s-build-biometric-support-hkf</link>
      <guid>https://dev.to/mikegrant/xamarin-let-s-build-biometric-support-hkf</guid>
      <description>&lt;p&gt;Biometrics is a commonly seen security feature on your phone. Whether it’s fingerprint or facial recognition, you’ll see it when you log in to your bank or using Google / Apple Pay. We’ll find out how to add biometric authentication to your Xamarin.Forms application.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Getting Started&lt;/li&gt;
&lt;li&gt;Configuring Android&lt;/li&gt;
&lt;li&gt;Configuring iOS&lt;/li&gt;
&lt;li&gt;Implementing the biometric check&lt;/li&gt;
&lt;li&gt;Testing&lt;/li&gt;
&lt;li&gt;Resources&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;Before we start adding support for Biometrics to our application, it’s worth understanding that this functionality works with the built in Biometric support of the OS on the users device. This &lt;strong&gt;&lt;em&gt;won’t&lt;/em&gt;&lt;/strong&gt; allow you to capture fingerprints within your app. This will ask the OS to prompt the user, and report back to your app whether they are authenticated or not.&lt;/p&gt;

&lt;p&gt;Add the &lt;a href="https://github.com/smstuebe/xamarin-fingerprint/"&gt;&lt;code&gt;Plugin.Fingerprint&lt;/code&gt;&lt;/a&gt; NuGet package to all of your projects (Shared and platform specific)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Rz36viVI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mikegrant.org.uk/assets/2021-03-08/nuget.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Rz36viVI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mikegrant.org.uk/assets/2021-03-08/nuget.webp" alt="Installing Plugin.Fingerprint NuGet Package"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Configuring Android
&lt;/h2&gt;

&lt;p&gt;For this to work properly, we need to ensure that the target SDK version for our app is greater than 6.0, and if you have migrated your Xamarin.Forms app to using the AndroidX packages then you won’t need to install the Xamarin.AndroidX.Migration NuGet package as the documentation suggests.&lt;/p&gt;

&lt;p&gt;To start, our app requires permissions to access the fingerprint.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;uses-permission android:name="android.permission.USE_FINGERPRINT" /&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--h6-dCz1V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mikegrant.org.uk/assets/2021-03-08/android-permissions.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--h6-dCz1V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mikegrant.org.uk/assets/2021-03-08/android-permissions.webp" alt="Android Permission Setup"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that the permissions are set up, the plugin needs to know which activity we’re working in so that it can show the prompt on the correct activity. As Xamarin.Essentials is bundled as part of a new Xamarin Project we’ll use that to establish the current activity (If you’re still using James Montemagno’s &lt;a href="https://github.com/jamesmontemagno/CurrentActivityPlugin"&gt;Current Activity Plugin&lt;/a&gt; then this will work as well).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CrossFingerprint.SetCurrentActivityResolver(() =&amp;gt; Xamarin.Essentials.Platform.CurrentActivity);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we’re using Xamarin.Essentials to help us work out the current activity, we need to ensure that the activity resolver is declared after we have initialised Xamarin.Essentials.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);

    Xamarin.Essentials.Platform.Init(this, savedInstanceState);
    CrossFingerprint.SetCurrentActivityResolver(() =&amp;gt; Xamarin.Essentials.Platform.CurrentActivity);
    global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
    LoadApplication(new App());
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Configuring iOS
&lt;/h2&gt;

&lt;p&gt;To start, our app requires permissions to access the fingerprint.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;key&amp;gt;NSFaceIDUsageDescription&amp;lt;/key&amp;gt;
&amp;lt;string&amp;gt;Need your face to unlock secrets!&amp;lt;/string&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Unlike with Android, that’s actually all that is required. Simple!&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing the biometric check
&lt;/h2&gt;

&lt;p&gt;Now that we have the the platform specific projects configured, we can move on to actually using the biometric authentication to check if a user is authenticated or not.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bool supported = await CrossFingerprint.Current.IsAvailableAsync(true);
if (supported)
{
    AuthenticationRequestConfiguration conf = new AuthenticationRequestConfiguration("Access your account", "Access your account");
    var result = await CrossFingerprint.Current.AuthenticateAsync(conf);

    if (result.Authenticated)
    {
        await DisplayAlert("Success!", "Authentication successful!", "Ok");
    }
    else
    {
        await DisplayAlert("Sorry!", "Authentication failed!", "Ok");
    }
}
else
{
    await DisplayAlert("Sorry!", "Biometrics are not available on your device", "Ok");
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are a couple of things happening in that sample, so lets pick out some of the key parts.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bool supported = await CrossFingerprint.Current.IsAvailableAsync(true);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will tell you whether Biometric is supported by the device that you’re running on. It’s always worth remembering that you need a fallback for users that either don’t enable biometrics, or their device doesn’t support it. Checking whether the authentication is available for use before using it is best practice.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AuthenticationRequestConfiguration conf = new AuthenticationRequestConfiguration("Access your account", "Access your account");
var result = await CrossFingerprint.Current.AuthenticateAsync(conf);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will configure the prompt that is shown to the user, (note: on iOS this will only take the title and ignore the description), and then return the result of that authentication.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (result.Authenticated)
{
    await DisplayAlert("Authenticated", "Congrats you were authenticated!", "Ok");
}
else
{
    await DisplayAlert("Sorry", "You were not authenticated", "Ok");
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will handle the result of the check, we simply want to check whether the returned value of Authenticated is true and you can then do the action you want, in the example we’re displaying an alert, for example taking the user to a secure page within your app, or before they take an action that you want to confirm the identity of the user.&lt;/p&gt;

&lt;p&gt;This should leave you with a prompt that looks similar to this: &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6c9w2ABN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mikegrant.org.uk/assets/2021-03-08/cover.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6c9w2ABN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mikegrant.org.uk/assets/2021-03-08/cover.webp" alt="Android and iOS Screenshots"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing
&lt;/h2&gt;

&lt;p&gt;You’re able to test biometric authentication in both the Android and iOS emulators. With Android, just ensure that you have setup the finger print within the specific emulator that you’re running.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;iPhone - Device &amp;gt; Features &amp;gt; Face ID &amp;gt; Enrolled&lt;/li&gt;
&lt;li&gt;Android - Settings (…) &amp;gt; &lt;code&gt;Touch the Sensor&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;p&gt;You can find a link to the GitHub repo with the code for this post &lt;a href="https://github.com/mike-grant/XamFormsBiometrics"&gt;here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>xamarinforms</category>
    </item>
    <item>
      <title>Xamarin Let’s Build - App Themes</title>
      <dc:creator>Mike Grant</dc:creator>
      <pubDate>Mon, 22 Feb 2021 00:00:00 +0000</pubDate>
      <link>https://dev.to/mikegrant/xamarin-let-s-build-app-themes-3h9</link>
      <guid>https://dev.to/mikegrant/xamarin-let-s-build-app-themes-3h9</guid>
      <description>&lt;p&gt;The theme of your app is what makes it stand out, fit in with your brand identity and create a lasting impression. With Xamarin.Forms it’s simple to implement multiple themes and styles, and then use them throughout your application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Defining the theme colours
&lt;/h2&gt;

&lt;p&gt;The most important aspect of styling your application is the colours that you use. When it comes to creating themes for your application, it’s a good idea to keep the colours separate from the rest of the theme. This allows you to make changes to the app colours without worrying about breaking other elements of the visual style as well as making generating new colour schemes for your app easier, as you won’t have to worry about copying the whole theme everytime you want to create a set of colours.&lt;/p&gt;

&lt;p&gt;Below is an example of a minimal set of colours for a light theme in Xamarin.Forms.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
                    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                    x:Class="XamarinFormsDarkTheme.Styles.LightTheme"&amp;gt;
    &amp;lt;Color x:Key="NavigationPrimary"&amp;gt;#2196F3&amp;lt;/Color&amp;gt;
    &amp;lt;Color x:Key="BackgroundColor"&amp;gt;#FFFFFF&amp;lt;/Color&amp;gt;
    &amp;lt;Color x:Key="TextPrimaryColor"&amp;gt;#B00000&amp;lt;/Color&amp;gt;
    &amp;lt;Color x:Key="TextSecondaryColor"&amp;gt;#800000&amp;lt;/Color&amp;gt;
    &amp;lt;Color x:Key="TextTernaryColor"&amp;gt;#C8C8C8&amp;lt;/Color&amp;gt;
&amp;lt;/ResourceDictionary&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Creating the app theme
&lt;/h2&gt;

&lt;p&gt;Now that we have the colours defined, we can use them to make our app pop. Currently, we’re not using any of the colours that we’ve defined in our app. To do this, we need to start building the app theme. Before we start, there are a couple of terms to be aware of when working with styles in Xamarin.Forms.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Explicit Styles - An explicit style is used for when you want to target a XAML element by using a key. These will have a &lt;code&gt;x:Key&lt;/code&gt; defined.&lt;/li&gt;
&lt;li&gt;Implicit Styles - An implicit style will apply to &lt;strong&gt;&lt;em&gt;all&lt;/em&gt;&lt;/strong&gt; XAML elements of the targetted type.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want more information regarding any of these terms, Microsoft’s documentation explains &lt;a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/styles/xaml/explicit"&gt;explicit&lt;/a&gt; and &lt;a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/styles/xaml/implicit"&gt;implicit&lt;/a&gt; styles in more detail.&lt;/p&gt;

&lt;p&gt;To start with, we need to import the colours that we defined earlier. This is achieved by adding a &lt;code&gt;ResourceDictionary&lt;/code&gt; to the &lt;code&gt;Application.Resources&lt;/code&gt; that references our colours. From there we can begin to build up the styles that we want to use throughout our application. I would recommend if you’re planning on adding theme switching of any kind (user selectable, or based on the device theme) to make sure that you reference the colours as a &lt;code&gt;DyanmicResource&lt;/code&gt;. This will allow you to update the resource dynamically, which is not achievable with a &lt;code&gt;StaticResource&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Below is an example of an app theme, using one set of colours&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="utf-8" ?&amp;gt;
&amp;lt;Application xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="XamFormsAppTheme.App"&amp;gt;
    &amp;lt;Application.Resources&amp;gt;
        &amp;lt;ResourceDictionary Source="/Themes/LightTheme.xaml"/&amp;gt;
        &amp;lt;Style TargetType="NavigationPage"&amp;gt;
            &amp;lt;Setter Property="BarBackgroundColor" Value="{DynamicResource NavigationPrimary}" /&amp;gt;
            &amp;lt;Setter Property="BarTextColor" Value="White" /&amp;gt;
            &amp;lt;Setter Property="BackgroundColor" Value="{DynamicResource BackgroundColor}" /&amp;gt;
        &amp;lt;/Style&amp;gt;
        &amp;lt;Style TargetType="Label"&amp;gt;
            &amp;lt;Setter Property="TextColor" Value="{DynamicResource TextPrimaryColor}" /&amp;gt;
        &amp;lt;/Style&amp;gt;
    &amp;lt;/Application.Resources&amp;gt;
&amp;lt;/Application&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s break the example code from above down further to examine what is happening.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;ResourceDictionary Source="/Themes/LightTheme.xaml"/&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will import the colours that we defined earlier, and make them available for use throughout your application. It’s merely a pointer to our LightTheme.xaml file and will make the colours that we have set in there available to use.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Style TargetType="Label"&amp;gt;
    &amp;lt;Setter Property="TextColor" Value="{DynamicResource TextPrimaryColor}" /&amp;gt;
&amp;lt;/Style&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is an implicit style, that will target all XAML elements with a type of &lt;code&gt;Label&lt;/code&gt;. We’re using the &lt;code&gt;TextPrimaryColor&lt;/code&gt; that we previously declared in LightTheme.xaml and we’re setting the TextColor to be that, in our example this will make all of the text contained in a &lt;code&gt;Label&lt;/code&gt; use the colour grey. Any property that you can alter on a XAML element can be overridden in this part.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;p&gt;If you want to read more about app themes, for example implementing dark mode, you can find more information in my other posts&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="///2020/05/03/automatic-dark-mode.html"&gt;Automatic Dark Mode&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="///2020/04/19/Supporting-Dark-Mode-with-Xamarin-Forms.html"&gt;Supporting Dark Mode with Xamarin.Forms&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can find a link to the GitHub repo with the code for this post &lt;a href="https://github.com/mike-grant/XamFormsAppTheme"&gt;here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>xamarinforms</category>
    </item>
    <item>
      <title>Xamarin Tips - Screenshot your Android Phone from ADB</title>
      <dc:creator>Mike Grant</dc:creator>
      <pubDate>Wed, 02 Sep 2020 23:00:00 +0000</pubDate>
      <link>https://dev.to/mikegrant/xamarin-tips-screenshot-your-android-phone-from-adb-2d5i</link>
      <guid>https://dev.to/mikegrant/xamarin-tips-screenshot-your-android-phone-from-adb-2d5i</guid>
      <description>&lt;p&gt;Having the ability to take a screenshot directly from your command prompt will save you a lot of time over the duration of a project. When I’m building an app I know I regularly take screenshots to show features, bugs or just general UI weirdness to others and the time I lose taking it, transferring it to be emailed or shared on Teams is frustrating. A handy one liner can be used to speed this process up.&lt;/p&gt;

&lt;h2&gt;
  
  
  Taking a screenshot on your Android device
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Using the adb command prompt from Visual Studio (Or if you have ADB in your path)
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;adb exec-out screencap -p &amp;gt; screenshot.png

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s it! Your screenshot is now saved to the location specified.&lt;/p&gt;

</description>
      <category>xamarinforms</category>
      <category>android</category>
      <category>adb</category>
    </item>
  </channel>
</rss>
