【问题标题】:Setting colour of application bar in C#在 C# 中设置应用程序栏的颜色
【发布时间】:2012-08-21 02:00:17
【问题描述】:

我在这样的代码中定义了我的 ApplicationBar:

private void BuildApplicationBar()
        {
            // Set the page's ApplicationBar to a new instance of ApplicationBar.
            ApplicationBar = new ApplicationBar();
            ApplicationBar.Opacity = 0.8;
            ApplicationBar.ForegroundColor = Color.FromArgb(0, 138, 204, 34);


            // Create a new button and set the text value to the localized string from AppResources.
            ApplicationBarIconButton CheckInExitAppBarButton = new ApplicationBarIconButton(new Uri("icons/check_in.png", UriKind.Relative));
            CheckInExitAppBarButton.Text = AppResource.CheckInExit;
            ApplicationBar.Buttons.Add(CheckInExitAppBarButton);
            CheckInExitAppBarButton.Click += new EventHandler(CheckInExitAppBarButton_Click);

        }

我可以看到图标的颜色发生了变化,但我看不到它们下面的文字。当我在没有 ApplicationBar.Color 的情况下执行此操作时,我可以同时看到图标 + 文本,但白色是我不感兴趣的

【问题讨论】:

  • 您要设置背景颜色还是前景颜色?
  • 前景。使用上面的代码,只有图标的颜色会发生变化。但下面看不到任何文字。
  • 是文字没设置还是颜色没变? AppResource.CheckInExit 设置是否正确?
  • 嗯,请看我的代码并发布。答案就在那里。文本已设置,AppResource 已正确设置。就在我想在 C# 中更改前景色时,图标的颜色发生了变化,但文本根本不可见......
  • “CheckInExit”有多少个字符

标签: windows-phone-7 application-bar


【解决方案1】:

文本使用前景色的 alpha 值,您将其设置为 0(透明)。改为将其设置为 255 即可:

    private void BuildApplicationBar()
    {
        // Set the page's ApplicationBar to a new instance of ApplicationBar.
        ApplicationBar = new ApplicationBar();
        ApplicationBar.Opacity = 0.8;
        ApplicationBar.ForegroundColor = Color.FromArgb(255, 138, 204, 34);


        // Create a new button and set the text value to the localized string from AppResources.
        ApplicationBarIconButton CheckInExitAppBarButton = new ApplicationBarIconButton(new Uri("icons/check_in.png", UriKind.Relative));
        CheckInExitAppBarButton.Text = AppResource.CheckInExit;
        ApplicationBar.Buttons.Add(CheckInExitAppBarButton);
        CheckInExitAppBarButton.Click += new EventHandler(CheckInExitAppBarButton_Click);

    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-18
    • 2021-07-11
    相关资源
    最近更新 更多