UWP AppBar color c# - c#

I'm trying myself at designing windows universal apps (windows 10), and in order that everything would look right, I wish to change application border color. I was checking forums earlier and non of the solutions seem right.
Thanks for all your time
Here is an example I have found, mint color even tho I have dark gray as my system color.

From UWP Windows 10 App, TitleBar and Status bar customization:
if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.ApplicationView"))
{
var titleBar = ApplicationView.GetForCurrentView().TitleBar;
if (titleBar != null)
{
titleBar.ButtonBackgroundColor = Colors.DarkBlue;
titleBar.ButtonForegroundColor = Colors.White;
titleBar.BackgroundColor = Colors.Blue;
titleBar.ForegroundColor = Colors.White;
}
}

Related

Change color of icons in status bar - Windows 10 Mobile UWP app

I have an uwp app published in Microsoft/Windows Store, and I want change color of icons in status bar.
I know change color of status bar background, but I can how change color of icons in status bar in Windows 10 Mobile?
Like this:
if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
{
var statusBar = StatusBar.GetForCurrentView();
if (statusBar != null)
statusBar.ForegroundColor = Colors.Red;
}
You'd also need to add reference to Windows Mobile Extensions into your project:

Black StatusBar with black font in Windows 10 mobile app

I have a Windows 10 UWP app running on mobile. When I run the app in an emulator, everything works fine. When I run it on a device (Lumia 550), the StatusBar is black with black font and the status indicators are not visible.
Is this some kind of bug?
I know I can force the StatusBar to have white background and black color, but the requirement for the app is to stick with the theme (black StatusBar in dark theme, white in Light theme).
If I create a new empty Windows 10 app and run it on a device, the problem is the same, it is not specific to my app.
Edit
Here's a more proper answer:
In Windows 10 Mobile the statusbar inherits it's background color from the topmost page. The foreground color is inherited from RequestedTheme.
This means that if you set the background color of your page to black and your RequestedTheme to Light (which gives a white foreground color), the text will be black on black.
Original post
Have you read this?: https://stenobot.wordpress.com/2015/07/08/uwp-app-development-styling-the-mobile-status-bar/
It might help you.
I have struggled with this a bit.
A strange thing is that when I start my app, the theme (Application.RequestedTheme) is always Light, ignoring the setting on the phone. Even when I try to set it to Dark in the constructor, it immediately reverts to Light. This could explain the black foreground color.
I also experience the inconsistency between simulator and device. To take care of that, I (as suggested in other answer) set the background color of the page (not the root Grid):
<Page
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
... >
</Page>
With this, the status bar at least appear readable.
If you got the black font on the black background with your Light theme project, simple add this line into OnLaunched method in App.xaml.cs:
rootFrame.Background = new SolidColorBrush(Colors.White);
Just add RequestedTheme="Dark"in App.xaml
In your reference Manager add Windows Mobile extensions for the UWP
Then in App.XAML.cs on
protected override void OnLaunched(LaunchActivatedEventArgs e)
add
if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
{
var statusBar = Windows.UI.ViewManagement.StatusBar.GetForCurrentView();
statusBar.BackgroundColor = Windows.UI.Colors.Green;
statusBar.BackgroundOpacity = 1;
statusBar.ForegroundColor = Colors.White;
}
If you want to change Title bar on PC version of UWP app, then you could use this
if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.ApplicationView"))
{
var titleBar = ApplicationView.GetForCurrentView().TitleBar;
if (titleBar != null)
{
titleBar.ButtonBackgroundColor = Colors.DarkBlue;
titleBar.ButtonForegroundColor = Colors.White;
titleBar.BackgroundColor = Colors.Blue;
titleBar.ForegroundColor = Colors.White;
}
}

Interactions with kinect version 2

I'm just starting developing with Kinect version 2 (SDK 2.0) and am trying out a windows store app with kinect support. I've followed one of microsoft's videos in order to set up basic interactions with a grid app. You add the following lines of code in the App.xaml.cs file:
KinectRegion region = new KinectRegion();
KinectUserViewer viewer = new KinectUserViewer() {
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Bottom,
Width = 121,
Height = 100
};
Grid grid = new Grid();
grid.Children.Add(region):
grid.Children.Add(viewer);
region.Content = rootFrame;
Window.Current.Content = grid;
I'm getting no error reports or exceptions and the user viewer comes up fine. There are no interactions however. Whatever I do I cannot get the hand icon to appear on screen like in the demo.
Any help or suggestions as to what's going wrong would be much appreciated.
P.S. I'm new to windows development, I have an Apple background.
I know you asked this a month ago, but have you turned on the Microphone and Webcam features in your Package.appxmanifest file? It's under the Capabilities tab.

How to Change the Color of Application Bar Buttons when Pressed

An interesting question, I was wondering if it is possible to theme the application bar buttons in Windows Phone 8 to use another color other than the current accent color as the background of the button when pressed. I am currently creating my app bar in code behind in my test application. Are there any suggestions of how to do this? I have not yet found a resource online anywhere. Essentially what I have right now is a very simple app bar for testing purposes.
MainPage.xaml.cs
private void BuildLocalizedApplicationBar()
{
// Set the page's ApplicationBar to a new instance of ApplicationBar.
ApplicationBar = new ApplicationBar();
// Create a new button and set the text value to the localized string from AppResources.
ApplicationBarIconButton newButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/new.png", UriKind.Relative));
newButton.Text = "new";
newButton.Click += newButton_Click;
ApplicationBar.Buttons.Add(newButton);
}
If you set the ApplicationBar's Foreground to something like #FFFEFEFE for white and #FF010101 for black the ApplicationBarIconButtons will not use the AccentBrush when they are pressed, they will use the defined Foreground Color of the ApplicationBar!
It took me hours to find the solution to that problem but it makes some sense: Microsoft uses White(#FFFFFFFF) and Black (#00000000) for their dark and light theme. In this case the ApplicationBar uses the AccentBrush and if the Foreground is set to a different color it uses the defined one.
So you just need to add the following line (white):
ApplicationBar.Foreground = new SolidColorBrush(Color.FromArgb(255, 254, 254, 254));

Transparent form background with MenuStrip?

According to a lot of questions here on SO, the best way to make the background of a form transparent is to set it to a fairly unused color (like Magenta) then set the form's TransparencyKey to that color.
this.BackColor = Color.Magenta;
this.TransparencyKey = Color.Magenta;
That part works fine. The problem that I'm running into is that it works fine except behind a MenuStrip. A semi-transparent background in the MenuStrip + transparent background in the form ends up like this:
That's what the MenuStrip looks like. The part where it turns magenta is when the MenuStrip itself is set to be semi-transparent.
This is what my form initialization function looks like:
public frmMain() {
this.TransparencyKey = Color.Magenta;
InitializeComponent();
this.BackColor = Color.Magenta;
if(Properties.Settings.Default.windowTheme == 0) { // theme is light
menuStrip.Renderer = new ToolStripProfessionalRenderer(new LightTheme());
}
else if(Properties.Settings.Default.windowTheme == 1) {
menuStrip.Renderer = new ToolStripProfessionalRenderer(new DarkTheme());
}
menuStrip.Invalidate();
}
And my custom renderer for the MenuStrip (colors are just for testing right now):
public class LightTheme: ProfessionalColorTable {
public override Color MenuItemSelected {
get { return Color.FromArgb(255, Color.Yellow); }
}
public override Color MenuStripGradientBegin {
get { return Color.FromArgb(255, Color.Black); }
}
public override Color MenuStripGradientEnd {
get { return Color.FromArgb(0, Color.Gainsboro); }
}
}
What I'm really trying to accomplish here is having the form transparent and part of the MenuStrip transparent so you can see the desktop underneath it. Is there a better way to do it, or a way to fix this?
public override Color MenuStripGradientEnd {
get { return Color.FromArgb(0, Color.Gainsboro); }
}
This is where the problem started, you specified an alpha of 0 for the gradient end color. Which works nicely, the alpha is blended well. But it is applied to the background color. So you see a blend of magenta. Which no longer matches the color key so the pixels become visible.
The layered windows feature built into Windows support two ways to blend a window against the desktop, the underlying winapi call is SetLayeredWindowAttributes(). Winforms supports the LWA_COLORKEY option, enabled by setting the TransparencyKey property, but not the LWA_ALPHA option. Called "per-pixel alpha". You'll find plenty of google hints on the pinvoke you'd need to enable it.
But you'll then be in for a rude surprise, you'll see that most of the controls in the toolbox stop working. Text rendering in Winforms is done by GDI, an api that renders text with an alpha of 0. With the inevitable side-effect that, when you turn on per-pixel alpha, that text is now transparent as well. Which you could call a feature but drastically impractical since you don't control the desktop color nor what windows are behind yours.
That's fixable as well by replacing controls and use a text rendering api like DirectWrite. But that's rather a lot of work and you just don't get much benefit from Winforms anymore. WPF supports per-pixel alpha, it doesn't use the standard Windows controls.

Categories