I have a problem developing a custom menu item.
The menu item is hosted in a ToolStripControlHost, the rest are just ToolStripMenuItems.
What I want is that when the user hovers the mouse over the custom control, to be selected like an ordinary ToolStripMenuItem, like in the image below. Unfortunately, I did not manage to figure this out. Is this behavior possible?
Edit: 26.10.2015:
I have been playing around with the control and it seems that the ToolStripControlHost, when added to the ContextMenu it is shrinked in the list, like in the image below.
I made the background of the custom control red so it can be seen better. The control only receives MouseHover events only when the mouse is over the control, shown in red. If you point the mouse on the left or the right, the ContextMenu receives the events.
ContextMenu custom menuitem
It is an interesting behaviour, because also the ToolStripTextBox or ToolStripCombobox don't take the whole left to right space and are not highlighted when mouse is over.
Now I hope someone has an idea how to do that.
Related
I am building a wpf ribbon application. When certain buttons are clicked on, I would like the background to remain "lit up" like when the mouse is over it. I don't want to change the default mouseover color, I just want to replicate it when the button is pressed for "modal" type commands. Is there a way to do this? In MFC programming it would be like adding the "BS_PUSHLIKE" style to the button where it remains lit while active. Thanks for any help you can provide.
I am not sure exactly what you are looking for, but I believe the equivalent of "BS_PUSHLIKE" in WPF is the ToggleButton control.
I have ComboBox which is data bounded to a collection.
I have customized the Vertical scroll bar of ScrollViewer, which will be in the center instead of normal right hand side of content presenter. It is working fine.
I have customized style for IsHighlighted trigger.
Issue: If I press the down repeat button it goes down and this is expected, but even if I disable the down repeat button, pressing on down repeat button highlights the item.
Any idea?
I don't fully understand the layout, a screen shot or a schematic drawing would help.
My guess is that you're using the "mouse over" and not the "mouse directly over" property to determine which element is under the mouse, so more than one element responds, but this is really a shot in the dark.
Actually the problem is in the ControlTemplate of ComboBox.
In ComboBox's control template I have used ScrollViewer and inside the ScrollViewer I used StackPanel. That is causing the issue.
Later I changed to ItemPresenter, now it is working fine.
I am working out of the 3.5 .Net Framework. I have a textbox next to a scroll bar in a stackpanel. I would like it to be that when the user clicks the "up" arrow of the scrollbar, the contents of the textbox are incremented, and decremented when the click the "down" arrow of the scrollbar. The problem is I am not sure which event I need to fire to do this. I've tried MouseDown, MouseUp, PreviewMouseDown (which fires but I don't know how to differentiate whether the up or down arrow was clicked), PreviewMouseUp (same problem), StylusUp, StylusDown, PreviewStylusDown, PreviewStylusUp, StylusButtonDown, StylusButtonUp, and the previews for that also. As I am debugging, I am using messageboxes to let me know I've entered that event, but none have shown (expcept for the PreviewMouseDown). Being fairly new to WPF, I am basically baffled.
Does anyone know which event I should be looking for? Thanks.
You should not abuse the ScrollBar for this but create a new control with two buttons.
I want a button that
Displays an image with NO border, NO background, NO text
If I tab into the imagebutton, THEN it shows the background and border
Also if I hover over it, it shows the background and border
I've searched and I've tried so many different things, but nothing it exactly what I want. I've tried setting various properties on the button to make the background and border transparent, but it still shows up. I've tried a style with a custom control template. I'd rather not have to completely reinvent all the triggers etc to get the button to render on mouse over. The biggest problem with custom control template is that then I loose all existing functionality and I'm basically building a new control from the ground up.
Here is another link that came closest to what I wanted but it doesn't properly work for me.
How do you completely remove the button border in wpf? - BUT.... for some reason the hover effect gets stuck. One I mouse over the image and the button border draws, it stays stuck on until I click somewhere else.
Actually, you will want to override the control template. You're not "losing" any functionality (aside from the UI triggers).
Original/Default Template -- This is a good starting point... copy/paste that into you're XAML (wherever you want to style this button... ie Button resources, UserControl/Window resources, App Resources?). From there make your adjustments.
Another easy way is to use Expression Blend. You can easily create a new template based on the existing template, and the styling/authoring tools it provides are much better than hand-coding XAML (unless you're good at doing that).
As far as displaying an image instead of text, just set the image as the content. A Button is a type of ContentControl which means that it can house any type of content (Object).
When the WPF ComboBox is clicked and in-focus, the only interaction that occurs after that can be with the ComboBox. If anything else is interacted with, including the window functions (minimize, restore, close, resize) and any control in the window, the action is ignored and the ComboBox loses focus.
In addition, MouseEnter and MouseLeave on the window buttons are still active, but when MouseEnter on the window border(?) occurs, the mouse pointer does not change to the resize pointer. This behavior makes sense because of the ComboBox's use of the popup control. The popup control exists independently of the main visual tree and if i.e. the window moves or gets resized, the popup remains fixed floating above the main window.
I have tried using Reflector, to see what the ComboBox is doing, but I have not been able to find what I am looking for. Basically, I do not know if this behavior is coming from the window, the ComboBox, or if it has something to do with the popup. How can I solve this problem?
You're right on in your description there, the popup keeps all action focus until it itself loses focus. If you're trying to change the functionality of the ComboBox you may want to look at creating your own ControlTemplate that behaves differently and does not keep the default action of the popup control.
Hope this helps, not entirely sure what you're trying to do.
I know this question is old, but for anyone coming here looking for the answer, it is to use Mouse.Capture.
The ComboBox sets Mouse.Capture(comboBox, CaptureMode.SubTree) in OnIsDropDownOpenChanged. This ensures that all mouse events are captured by the ComboBox. When the Popup is closed Mouse.Capture(null) releases the mouse capture.