I am trying to change the color of the button in my Universal App.
This is the line:
Button.Background = new SolidColorBrush(Color.FromArgb(a,r,g,b));
But i get the error saying 'Color' does not exist in current context...
Do i need to include something or?
The Color is declared in Windows.UI;
Related
On Windows, once a Static control has been painted (it is already shown), how can we retrieve its text color ?
I have tried with GetTextColor(), GetDCPenColor() but they don't work.
thanks
GetSysColor(COLOR_BTNTEXT) or GetThemeColor if you are using Visual Styles. A subclassed control might change the default by handling WM_CTLCOLORSTATIC.
I can't work out how to change IOS's status bar in nativescript without the requirement of having an ActionBar / NavigationBar.
I've tried:
var navController = frame.topmost().ios.controller;
let navigationBar = navController.navigationBar;
navigationBar.barStyle = UIBarStyle.Black;
But this totally fails when there is no ActionBar!
This solution works!
Step 1:
Add the below to app/App_Resources/iOS/Info.plist.
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
It will do the following:
Set default color for the splash screen and app to white.
Allow you to change the status bar color within the app.
Step 2:
After adding that you can then use the below snippet to change the status bar style color:
// white status bar text
UIApplication.sharedApplication.setStatusBarStyleAnimated(UIStatusBarStyle.LightContent, true);
// black status bar text
UIApplication.sharedApplication.setStatusBarStyleAnimated(UIStatusBarStyle.Default, true);
Optional But Important Step 3:
If you want to change the status bar as soon as the application finishes loading (after splash screen) or when it becomes active then you'll need to set the above snippet inside a UiApplicationDelegate function. See link for example:
https://docs.nativescript.org/core-concepts/application-lifecycle#ios-uiapplicationdelegate
#Jammer answer is correct, i was able to set the color of the status bar text using this method on Nativescript-Angular, is important to mention, you need to clear your build/cache folder (tns platform remove ios) to update configurations on next build every-time you update Info.plist, this small bug happens even on NS7+
Note: you also need tns-platform-declarations to avoid common typescript errors. Also remember this is just for iOS so it is required to add validations to avoid any issue on Android.
I am working on VB6 environment.
I have a textbox whereby i need to change its background color based on my setting.inf file.
TextBox.BackColor = "&H00C0FFFF&"
I wanted to change it to this yellow color value(&H00C0FFFF&) but unable to get it working.
Any idea what is wrong?
resolved.
The value cannot be a string.
TextBox.BackColor = &H00C0FFFF&
I'm using Windows.UI.ViewManagement.UISettings to get system accent color but it seems this class does not have any method or property for light/dark mode. I failed to find a document for this feature, how can I detect this?
PS: I'm making a JS app which does not have access for Windows.UI.Xaml namespace.
You can create a Windows Runtime Component project in your solution from there you access Windows.UI.Xaml namespace. Add a method to check current ApplicationTheme like that.
public sealed class Test
{
public static string CurrentTheme()
{
var isDark = Application.Current.RequestedTheme == ApplicationTheme.Dark;
if (isDark)
return "Dark";
return "Light";
}
}
Add reference to windows runtime component project in your javascript app project and you can call this method where ever you want to check application theme. Take a look here for walkthrough on createing Windows Runtime Component.
I have found an easier solution, which should work in JavaScript apps as well, without requiring the Windows Runtime Component - the UISettings class:
var uiSettings = new Windows.UI.ViewManagement.UISettings();
var color = uiSettings.getColorValue(
Windows.UI.ViewManagement.UIColorType.background
);
The color you get is either black for dark theme or white for light theme.
The class also has very useful event ColorValuesChanged which you can use to observe theme changes at runtime.
For Windows 10, the value of the AppsUseLightTheme property in the path HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize of the registry specifies wherever Windows is in dark or light mode.
You can read the registry if the theme is enabled for the current user and get the setting from there. Something like this...
private const string RegistryKeyPath = #"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize";
private const string RegistryValueName = "AppsUseLightTheme";
private static ApplicationTheme GetWindowsTheme()
{
using var key = Registry.CurrentUser.OpenSubKey(RegistryKeyPath);
var registryValueObject = key?.GetValue(RegistryValueName);
if (registryValueObject == null)
{
return ApplicationTheme.Light;
}
var registryValue = (int)registryValueObject;
return registryValue > 0 ? ApplicationTheme.Light : ApplicationTheme.Dark;
}
Full example can be found in this link
https://engy.us/blog/2018/10/20/dark-theme-in-wpf/
Before the Windows Anniversary update you could not do that. The application theme was always the one you set in the App.xaml file:
<Application
...
RequestedTheme="Dark">
</Application>
Now with the new Anniversary Update, you can remove this line from the App.xaml file, which will make the app honor the user's system settings.
The RequestedTheme enumeration has actually three values - Dark, Light and Default. Default is the value that reflects the system settings, Dark and Light force the theme.
If you want to actually detect the current theme in code when App's RequestedTheme is Default, you will probably need to check the some color resource like SystemAltHighColor for its value, because that will give you an idea of what theme is currently set.
ThemeResources have been introduced in 8.1 and their behavior is similar in W10. Therefore you can define suitable resource in ThemeDictionaries responsible for available Themes and then you can check the defined resource when you whant to know which Theme is currently used.
The code will be very similar to the one in this answer.
If you want to get the Value in PowerShell you can use the following code:
(New-Object Windows.UI.ViewManagement.UISettings).GetColorValue("background")
I have a project that I need to change overall color themes in the app. A lot of my UI elements are built through Interface Builder in Xcode 6.1. I need to set colors as variables in interface builder, so if I set a preprocessor telling the app to use a certain scheme then the colors will change in interface builder. Is this even possible?
I'm not aware of any way to do this with interface builder, however there is a way that you can set appearance properties in code for many IOS UI elements that will then apply globally. As an example see the following snippet of code:
UIToolbar.appearance().tintColor = UIColor.whiteColor()
UIToolbar.appearance().barTintColor = UIColor.blackColor()
UITableView.appearance().separatorColor = UIColor.grayColor()
UITableView.appearance().sectionIndexColor = UIColor.grayColor();
UINavigationBar.appearance().tintColor = UIColor.blueColor()
UINavigationBar.appearance().barTintColor = UIColor.blackColor()
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor()]
The code sets a the default tint and bar color for all the UIToolbars, separator and section index colors for all UITableViews, and appearance properties for all the UINavigation views in my app..
You could use #if to set the appearance differently depending on the environment variables set in the compiler.
If you want to find out more about how this works Id suggest reading Apples documentation on UIAppearance properties here:
UIAppearance Documentation
Color variables are awesome, I wish xcode had this too.
Turns out you can add a color variables feature.
This xcode plugin, called Suggested Colors, let's you build and use a palette of colors in Interface Builder. It uses a plist file, So I think you could read that in code and have a color palette shared between code and IB this way. Looks promising. Unfortunately, doesn't seem to work on xcode 6.3.2. Hope it gets fixed.