【问题标题】:How do you change the background colour of the toolbar on Windows Phone in Xamarin Forms?如何在 Xamarin Forms 中更改 Windows Phone 上工具栏的背景颜色?
【发布时间】:2016-03-08 07:19:00
【问题描述】:

我们正在使用 Xamarin 表单(最近升级到 2.0.0.6484)。我们的目标是 iOS、Android 和 Windows(8.1 和 UWP)。我们在 Windows 平台上逐页向工具栏添加项目,例如ToolbarItems.Add(new ToolbarItem("Sample", "icon.jpg", () => { }));。现在我们想改变它的背景颜色。

我可以在本机 Windows 环境中轻松执行此操作,如图所示,但是您似乎无法在 Xamarin Forms 中执行此操作,因为没有呈现器或相关属性公开。

查看Xamarin Forums 上的问题,我们发现一年前的问题(类似性质)尚未解决。

那么我们如何在 Xamarin Forms 中改变 CommandBar 的背景颜色呢? 或者我们怎样才能避免这个问题?

【问题讨论】:

    标签: c#-4.0 xamarin xamarin.ios windows-phone-8.1 xamarin.forms


    【解决方案1】:

    在 App.xaml 中执行此操作

    <Application.Resources>
            <ResourceDictionary>
                <Color x:Key="mRed">#DD0000</Color>
                <Color x:Key="mWhite">#FFFFFF</Color>
    
                <Style TargetType="NavigationPage">
                    <Setter Property="BarBackgroundColor"  Value="{ StaticResource mRed}"/>
                    <Setter Property="BarTextColor"  Value="{ StaticResource mWhite}"/>
                </Style>
            </ResourceDictionary>
        </Application.Resources>
    

    Visual Studio 2017 Sample Project - Screenshot

    【讨论】:

      【解决方案2】:

      您需要在本机级别执行此操作,因为我不知道任何公开的属性。

      Windows 手机

      this.ApplicationBar.BackgroundColor = 
      

      iOS 和 Android 没有 ApplicationBar,它们将任何工具栏项放在 NavigationBar 中

      NavigationPage.BarBackgroundColor =
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-09
        • 1970-01-01
        • 1970-01-01
        • 2021-04-13
        • 2017-10-03
        • 2016-04-21
        相关资源
        最近更新 更多