WPF menuitem shortcut. Strange behaviour - wpf

I create a menu item (context menu if that is of any help) using:
MenuItem menExit = new MenuItem();
menExit.Header = "Exit"; // will be changed later
menExit.Command = UICommands.CmdExit;
menExit.CommandBindings.Add(new CommandBinding(UICommands.CmdExit, CmdExitExecute, CmdExitCanExecute));
menu.Items.Add(menExit);
It works very well with one exception. No matter what CmdExitCanExecute returns, the menu item shortcut is ALWAYS grayed out. Note that the text ("Exit") works as intended (grayed out when CmdExitCanExecute returns false and black when true) but not so the shortcut. To make matters more complicated: the shortcut works when I press the key combination. What do I need to do to make the shortcut show the right color? The menu is shown by right clicking a tray icon, but that shouldn't matter, should it?

I suspect this is how the WPF default style works. If you actually disable a menu item, you will find that the shortcut text is a slightly lighter grey. The shortcut on a non-disabled item is slightly darker grey while the menu item text is black.
The difference is subtle and confusing but I think your MenuItem is working correctly.

Related

Why is the Designer in Codename one not reporting the attributes I set?

I started a Codename One project with the "Hello World bare bones". I used to define the styles in the Theme tab from the Designer but now it is becoming tedious.
Actually for some selectors, even if I override (unchecking the Derive box) some properties the style is not changed in the Designer (see below) or in the app itself.
However, in the list of selectors, the color is not the one I selected but the alignment seems to be it.
It seems that the theme is locked somewhere. Do I make a mistake, or should I set a constant to "unlock" the theme, or even should I clear some directories?
Please note that I am using NetBeans with designer V 1.1
.
Edit March 1st 2017
Following #Diamond's great tips, I was able to change the foreground color by setting the Border to empty (instead of NULL). However now the alignment is still not what I expect (see below). How can I do for this property ?
Any help appreciated,
In the Designer, Border is superior to background color and background image. Which means if the border image is set, a background color will have no effect unless the border is just a stroke or line.
Always solve this with these few steps:
Go to the Border tab and uncheck the override.
Click the ... button next to Border Help and a new Dialog will show.
Change the Type (First line) to Empty and click Ok.
Your background color will now have an effect.

Setting colors for the overflow menu

I'm trying to set the colors of the menu items for the overflow menu. The unselected style works just fine, but the first item shows up pre-selected, which means I get white text with a white icon on a white background. I can make it legible by setting the text color to black, but I still lose the icon, and anyway, I don't want a white background. I'm setting these in the resource editor using the Command UIID, but it seems to be ignoring my settings for selected and/or pressed styles. Am I doing something wrong? Or is this a bug in the code? (I'm using a modified version of the Blue theme.)
In the illustration, I have set a padding of 1 mm top and bottom, and a margin of 0 all the way around.
Try setting the bgTransparency of the CommandFocus UIID to 0.

Specifying animations and Toolbar items in the resource editor

I'm getting the hang of using themes to change my app's look and feel, but there are still a few mysteries. Right now, in the SocialBoo theme, the button to show the overflow menu is way too small, even though it's the right size in any other theme. Also, the overflow menu pops up with a nice animation on the other themes, but not in the SocialBoo theme. Can anyone tell me how to modify the theme to fix the size of the overflow button and specify an animation for the overflow menu?
SocialBoo is a pretty old demo that still uses the old GUI builder. We are slowly migrating away to the new GUI builder which was slated for the 3.4 release but is currently still considered beta status.
The new GUI builder standardizes on Toolbar which didn't exist when we developed the old GUI builder.
The icons for overflow/side menu can be customized via theme constants specifically sideMenuImage and menuImage.
I was able to partly fix this in code like this:
Hashtable<Object, Object> newThemeProps = new Hashtable<>();
// I need to start these with #, which tells the addThemeProps() method
// that these are theme constants, not theme properties.
// (The # character gets stripped out.)
newThemeProps.put("#menuTransitionIn", "bubble");
newThemeProps.put("#menuTransitionOut", "fade");
UIManager.getInstance().addThemeProps(newThemeProps);
This gave me the animations I wanted. I still don't know how to change this in the resource file.
As for the buttons, I fixed this in the Resource Editor by opening the TitleCommand style and setting the Background Image type to [empty] in the "..." button. This didn't improve the size of the button, but it removed the too-small button image, so it looks more professional. Here's what it looks like before the fix:
This is after the fix:
(Yeah, I added another item to the menu, too.)
It retrospect, I could probably have just checked the Derive button in the Background Image tab.
I also changed the TitleCommand foreground color to white (not shown), because the black buttons were practically invisible.
Finally, I changed the FontImage Icons to white with this piece of code:
/**
* The icon created by this method gets passed to the Command constructor.
*
* #param icon The FontImage constant for the desired icon
* #return The icon as an Image.
*/
#Nullable
public static Image createClearMaterialIcon(char icon) {
materialIconStyle = UIManager.getInstance().getComponentStyle("TitleCommand");
// materialIconStyle.setBgTransparency(0, true);
if (icon == 0) {
return null;
} else {
return FontImage.createMaterial(icon, materialIconStyle);
}
}
The transparency of the style needs to be set to zero (transparent). This can be done using the setBgTransparency() call in the line that's commented out, or it can be done by setting the TitleCommand resource's transparency to 0 in the Color tab.
Thank you, Shai, for pointing me in the right direction.

Ellipse as mask for a label

I'm making a toggle button with a new design "material design" like. I have a problem with animation. I'm using an ellipse that expands and changes the color of the button where the mouse clicked. With color it works well but I want to make visible label as ellipse is over it and invisible the second one. I have an image to make it simplier to understand:
so the second image shows that where the green is it stills writes "Toggled" where it should already write "Untoggled" but still where blue color is, there should be writed "Toggled" then radialy changes. I have tried to use Opacity Mask but I couldn't get it to work. Anyone could help me?
Ok I did it animating EllipseGeometry, settings the label I want to display on top of the old one and clipping the top one to the EllipseGeometry.

WPF: Changing the look of a Surface Listbox "click-effect"

I'm changing the look of some Controls that I use in my Microsoft Surface Application at the moment. And today I'm working on a SurfaceListBox.
I have the template for it and already changed background and borders and other stuff.
But I really cannot find where I can change the color of the rectangle that appears on the ListBoxItem when you touch the ListBox. At the moment it's just white and I want to change that.
It's not something like the effect that you can see when the item is selected. I already found that and changed that so my selected item now appears in a different color. But the effect in the second when you touch the item stays white.
So where can I change this effect?
If you mean the bright, white highlight that happens when you press your finger against an item you should look into the SurfaceShadowChrome. It's used by (almost) all surface controls to give feedback when the user is pressing on a control.
It does have a Color property that you can modify to suit your needs. Apart from the color, and the tweaking of corner radius and shadow offset, it's not a very flexible decorator. But hopefully, you'll be able to make it do what you need.

Resources