【问题标题】:automatic button icon support for themes Windows phone主题 Windows 手机的自动按钮图标支持
【发布时间】:2014-09-05 12:23:10
【问题描述】:

WP 支持深色和浅色主题。用户可以将手机上的主题更改为浅色或深色,具体属性也会随之变化,例如文字颜色等。

我正在尝试创建包含图标图像的按钮,以自动更改以支持用户选择的主题。

有没有简单的方法可以做到这一点?

这是我目前使用按钮的方式:

    <Button Name="button" Margin="250,443,86,44" VerticalAlignment="Center" Style="{StaticResource roundButton}" Height="120" Click="button_click" HorizontalAlignment="Center" Width="120">
            <Image Source="/Assets/Tiles/picture.png" HorizontalAlignment="Left" VerticalAlignment="Center" />
    </Button>

【问题讨论】:

  • 这是用于应用栏,还是在页面内?
  • 抱歉,在页面内。
  • 你能展示一下你的辛苦吗?
  • 如果答案令人满意,请将其标记为正确,以便对其他人也有帮助

标签: windows-phone-7 button windows-phone-8 windows-phone themes


【解决方案1】:

你可以做这样的事情。您可以检测应用程序运行时设置的主题,并相应地更改您的 UI 元素。我在 MainPage.xaml 页面的 OnNavigatedTo 方法中执行此操作以更改 MainPage.xaml 中的元素

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    base.OnNavigatedTo(e);
    var theme = (Visibility)Resources["PhoneLightThemeVisibility"];

    if (theme == System.Windows.Visibility.Visible)
    {
        // Change the UI for Light theme
    }
    else
    {
        // Change the UI for Dark theme
    }
}

试试这个。这应该适合你。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-08
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 2011-11-06
    • 1970-01-01
    • 2021-11-25
    相关资源
    最近更新 更多