4
votes

I'm trying to get the Fluent Design working on my Xamarin.Forms UWP App. I've tried different methods using a Renderer, Overwriting Styles but none of them work.

The Acrylic brush always falls back to the FallbackColor.

Setup:

Target version: Windows 10 (1803) Min version: Windows 10 Fall Creators Update(16299).

and I'm also checking

Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.Xaml.Media.AcrylicBrush") wich are available.

Using any of the predefined Acrylic brushes results in "Cannot find a Resource with the Name/Key SystemControlChromeLowAcrylicWindowBrush".

AcrylicBrush & Splitview Style:

<media:AcrylicBrush x:Key="HostBackdropBrush"
                    BackgroundSource="HostBackdrop"
                    TintColor="White"
                    TintOpacity="0.4" 
                    FallbackColor="WhiteSmoke" />


  <Style TargetType="SplitView">
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="VerticalContentAlignment" Value="Stretch"/>
        <Setter Property="OpenPaneLength" Value="{ThemeResource SplitViewOpenPaneThemeLength}"/>
        <Setter Property="CompactPaneLength" Value="{ThemeResource SplitViewCompactPaneThemeLength}"/>
        <Setter Property="PaneBackground" Value="{StaticResource HostBackdropBrush}"/>
    </Style>

Custom Renderer:

[assembly: ExportRenderer(typeof(MasterPage), typeof(MasterPageRenderer))]
namespace MasterDetailPageNavigation.UWP
{
    class MasterPageRenderer : PageRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
        {
            base.OnElementChanged(e);
            if (e.OldElement != null || Element == null)
            {
                return;
            }

            try
            {
                if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.Xaml.Media.XamlCompositionBrushBase"))
                {
                    Windows.UI.Xaml.Media.AcrylicBrush myBrush = new Windows.UI.Xaml.Media.AcrylicBrush();
                    myBrush.BackgroundSource = Windows.UI.Xaml.Media.AcrylicBackgroundSource.HostBackdrop;
                    myBrush.TintColor = Windows.UI.Color.FromArgb(255, 200, 200, 200);
                    myBrush.TintOpacity = 0.2;

                    Background = myBrush;
                }
                else
                {
                    SolidColorBrush myBrush = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 240, 240, 240));

                    Background = myBrush;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }

        protected override Windows.Foundation.Size ArrangeOverride(Windows.Foundation.Size finalSize)
        {
            return base.ArrangeOverride(finalSize);
        }

    }
}
    ```


2
Please have a look at this item : stackoverflow.com/a/13563083/4373895 - VikrantMore
Thanks! this fixed my problem! Can you make an answer so I can reward you? - iNCEPTiON_
Sure iNCEPTION_ Thats a great news - VikrantMore

2 Answers

1
votes

Please have a look at the Link

This should solve your problem. You can resolve the issue by adding ThemeResources.xaml to the project resources.

0
votes

Your AcrylicBrush and style worked well on my side. Please check 'Winbdows Settings -> Personalization -> Colors -> More Options -> Transparency effects'. You need to turn on the the Transparency effects.

enter image description here