简体   繁体   English

在Windows Phone中将用户输入上的应用程序主题从暗更改为亮,反之亦然

[英]Change app theme on user input from dark to light and vice versa in Windows Phone

I am developing an application, where I need to give user an option to change theme of app at any point of time through settings from dark to light and vice versa and can switch the theme at any time. 我正在开发一个应用程序,我需要给用户一个选项,可以通过从暗到亮的设置随时更改应用的主题,反之亦然,并且可以随时切换主题。

Please let me know if there is a way to do it. 请让我知道是否有办法。

Currently the app changes theme according to OS theme. 目前,该应用根据操作系统主题更改主题。 If user has dark theme selected in OS, app will have dark theme and vice versa. 如果用户在OS中选择了深色主题,则应用将具有深色主题,反之亦然。

Requirement is irrespective of OS theme user should be able to change theme inside application (Like in Google Mail/ VLC player settings etc.) 要求与OS主题无关,用户应该能够在应用程序内部更改主题(例如Google Mail / VLC播放器设置等)

Please help me out in implementing this. 请帮助我实施此操作。

If you made the application switch with the OS Theme by using the global resource keys for colors, icons and brushes you would have to replace all of that; 如果通过使用全局资源键来使用颜色,图标和画笔来使应用程序切换为带有OS主题,则必须全部替换掉​​; as far as I know there is no way to intercept that. 据我所知,没有办法拦截它。

To have the application switch between themes you could define a property on the main viewmodel that can be accessed and bound to from anywhere. 要使应用程序在主题之间切换,可以在主视图模型上定义一个属性,该属性可以从任何地方访问和绑定。 Put all the colors and resources you want to theme in a ViewModel and bind to these properties. 将要主题化的所有颜色和资源放入ViewModel中并绑定到这些属性。 Next create some value converters to turn a general resource reference into a themed resource reference. 接下来,创建一些值转换器,以将常规资源参考转换为主题资源参考。 That will allow you to specify a color by a logical name and have the converter translate it to a theme aware color: 这将允许您通过逻辑名称指定颜色,并使转换器将其转换为主题感知的颜色:

<Text Background="{Binding Path=UIResources.TextBackground, 
                           Converter={StaticResource ColorToThemedColor}}" />

You could bind the RequestedTheme of your pages to a bool-Value. 您可以将页面的RequestedTheme绑定到bool-Value。

Then write a value-converter, which returns Light or Dark for true/false, an set it as Page-Resource. 然后编写一个值转换器,将true / false返回为Light或Dark,并将其设置为Page-Resource。

Last you have write a static Property, to save the value through navigation. 最后,您编写了一个静态属性,以通过导航保存值。

Initialize the static value on start up, and every constructor of you viewmodel get's the value at sets the isLight-Property on the Page 在启动时初始化静态值,并且viewmodel的每个构造函数都在页面上设置isLight-Property时获得该值

<Page RequestedTheme={Binding isLight,Converter={Staticresource TruetoLightConverter}>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当 Windows 10 从深色主题更改为浅色时,如何更改 uwp 应用程序标题栏颜色,反之亦然? - How to change uwp app title bar color when Windows 10 change from dark theme to light and vice versa? 使用 python 在 windows 10 中查找主题是深色还是浅色 - Find if theme is dark or light in windows 10 using python 有没有办法从 Windows 主机访问 WSL 文件夹,反之亦然? - Is there a way to access a WSL folder from the Windows host or vice versa? #UWP获取系统主题(浅色/深色) - #UWP get system theme (Light/Dark) 如何更改Windows Phone 8.1主题颜色 - How to change the Windows Phone 8.1 theme color 用于windows的Eclipse黑暗主题:如何将滚动条和标题栏的颜色更改为黑暗? - Eclipse dark theme for windows: how to change the color of scroll bars and title bars to dark? 用于在Windows上更正Linux文件名的脚本,反之亦然? - Script for correcting linux filenames on windows and vice versa? C - 在UNIX上编写Windows编译和反之亦然 - C - Writing On Windows Compiling On UNIX And Vice Versa 如何将 Windows 任务栏从“显示”切换到“自动隐藏”(反之亦然)? - How to toggle/switch Windows taskbar from “show” to “auto-hide” (and vice-versa)? 匹配的Windows系统颜色:暗上亮 - Matching windows system colors: light on dark
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM