Xamarin.Forms问题中的流利设计

时间:2019-01-25 09:55:06

标签: c# xamarin.forms uwp xamarin.uwp

我正在尝试在Xamarin.Forms UWP App上使用Fluent Design。我尝试了使用“渲染器”,“覆盖样式”的不同方法,但是它们都不起作用。

丙烯酸画笔始终回落到FallbackColor。

设置:

目标版本:Windows 10(1803) 最低版本:Windows 10 Fall Creators Update(16299)。

我也在检查

Windows.Foundation.Metadata.ApiInformation.IsTypePresent(“ Windows.UI.Xaml.Media.AcrylicBrush”)均可用。

使用任何预定义的Acrylic画笔都会导致“找不到名称/键为SystemControlChromeLowAcrylicWindowBrush的资源”。

AcrylicBrush和Splitview样式:

<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>

自定义渲染器:

[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 个答案:

答案 0 :(得分:1)

请看看Link

这应该可以解决您的问题。您可以通过将ThemeResources.xaml添加到项目资源中来解决此问题。

答案 1 :(得分:0)

您的AcrylicBrush和样式对我而言效果很好。请检查“ Windows设置->个性化->颜色->更多选项->透明效果”。您需要打开透明效果

enter image description here