Implementing the ButtonShadowEffect RoutingEffect class

In this section, we will begin creating the ButtonShadowEffect class for the shared project section of our TrackMyWalks solution. This class will essentially contain a routing reference to our platform-specific class used by our ButtonShadowEffect class. Since we cannot directly reference PlatformEffects classes that have been created for each platform, we will need to create a RoutingEffect class, referencing the same name as we defined in each platform, so that it will make it much easier to access these in our XAML pages that utilize this effect.

Let's start by creating the ButtonShadowEffect RoutingEffect class for our TrackMyWalks app by performing the following steps:

  1. Ensure that the TrackMyWalks solution is open in the Visual Studio for Mac IDE.
  2. Right-click on the TrackMyWalks shared project and choose Add | New Folder from the pop-up menu and enter CustomEffects for the name of the new folder to be created.
  3. Right-click on the CustomEffects folder and choose Add | New File... from the pop-up menu, as shown in the following screenshot:

Creating a New File within the CustomEffects Folder

  1. Create a new Empty Class called ButtonShadowEffect in the CustomEffects folder, as shown in the following screenshot:

Creating the ButtonShadowEffect Class
  1. Ensure that the ButtonShadowEffect.cs file, which is located as part of the TrackMyWalks group, is displayed in the code editor and enter the following code snippet:
     //
// ButtonShadowEffect.cs
// Creates a Button Shadow Effect using the
// RoutingEffect Class
//
// Created by Steven F. Daniel on 16/07/2018.
// Copyright © 2018 GENIESOFT STUDIOS. All rights reserved.
//
using Xamarin.Forms;

namespace TrackMyWalks.CustomEffects
{
public class ButtonShadowEffect : RoutingEffect
{
public ButtonShadowEffect() :
base("GeniesoftStudios.ButtonShadowEffect")
{
}
}
}

Let's now take a look at what we covered in the preceding code snippet:

  1. We started by including references to the Xamarin.Forms namespace, so that we can access the classes that are defined in these namespaces.
  2. We ensured that our ButtonShadowEffect class inherits from the RoutingEffect class, so that we can access each of the platform-specific method implementations of the PlatFormEffect class.
  3. We created the ButtonShadowEffect class constructor and ensured that this inherits from the base class that points to the ResolutionGroupName and PlatformEffect assembly attributes in our platform-specific ButtonShadowEffect class, so that we can reference this in our XAML pages.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.182.76