UWP – Using an Acrylic Brush in your Xamarin Forms MasterDetail menu

Right, so you are one of those guys targeting UWP with their Xamarin Forms app… aand you want to use the new Acrylic brush to make you application stand out. Say no more.

We won’t be using any 3rd party library/package to do this and we’ll be working in the platform specific project; so open up your MainPage.xaml.cs found inside your UWP project. First thing we need to do is grab a reference to your MasterDetail Master page. In my case, the MasterDetail represents my MainPage so things are pretty straight forward.

Next, you need to the native renderer for the Master page. This is what will allow us to modify the Background brush.

var renderer = Platform.GetRenderer(masterPage) as PageRenderer;

Now create your brush and assign it to your renderer. This will overwrite any BackgroundColor that you might have set on your ContentPage in XAML – and this is good, Android and iOS will continue to use that value you defined in XAML while on UWP you will be using the new AcrylicBrush.

I’ve set the TintColor and FallbackColor to match the color that I’ve set in XAML, while for the opacity I chose to go with 80%. Play with these values until you obtain the desired effect. As for what each of the properties does exactly:

TintOpacity: the opacity of the tint layer. We recommend 80% opacity as a starting point, although different colors may look more compelling at other transparencies.

BackgroundSource: the flag to specify whether you want background or in-app acrylic.

FallbackColor: the solid color that replaces acrylic in low-battery mode. For background acrylic, fallback color also replaces acrylic when your app isn’t in the active desktop window or when the app is running on phone and Xbox.

You can read this for more info on how the Acrylic material works. Also, just in case something doesn’t work, here’s the whole MainPage: