Tony B

Has anyone noticed that the style specified by FocusVisualStyle on a textbox (or button or anything I imagine) does not get applied if you click on the control

It works fine if you tab to the control but not if you click on it. The doc says that if the control has the keyboard focus, the FocusVisualStyle will be applied but this is clearly not the case as a control you click on receives both the keyboard and logical focus.

Am I missing something This sure looks like something too obvious to be a bug...



Re: Windows Presentation Foundation (WPF) FocusVisualStyle is not applied when focus is moved with the mouse ??

Yi-Lun Luo - MSFT

Hello, this is the desired behavior. FocusVisualStyle only applies to the Control when it is focused via keyboard navigation. Try to open a Win32 dialog with more than one Control. If you simply click on a Button, will a dashed border appear ItĄŻll only appear when you use keyboard to focus it. If you need a different appearance for your control when it is mouse focused, you should use a Trigger for IsFocused property in your normal style.






Re: Windows Presentation Foundation (WPF) FocusVisualStyle is not applied when focus is moved with the mouse ??

GP_S

Hi, I am seeing inconsistent behavior of Focus Visual. On my development PC, a control gets focus and the focus visual (dotted frame) is shown when i click the control, however, the focus visual dissapeared when I run the same binaries on another PC which doensn't have Visual Studio installed (and I am pretty sure the control does get keyboard focus after it is clicked).

Both PC have the same versions of .net frameworks installed. I am wondering what causes the problem





Re: Windows Presentation Foundation (WPF) FocusVisualStyle is not applied when focus is moved with the mouse ??

Dr. WPF

Try snooping the app to see where the focus is going. It may be on a child of the control.

You can snoop the properties of the control directly to see the values for IsFocused, IsKeyboardFocusWithin, etc., but I find it much more convenient to just snoop the FocusManager.FocusedElement property.

If for some reason you cannot snoop the app, just add a TextBlock somewhere in your UI and bind its Text property to FocusManager.FocusedElement. This will at least point you in the right direction. Or if you want to track the focus in code, you can override the metadata for FocusManager.FocusedElementProperty for all dependency objects to add a property changed callback. Then you can spit out debug information or even use a breakpoint and break when the focus changes.

Feel free to ping me if you'd like sample code for any of these latter approaches.






Re: Windows Presentation Foundation (WPF) FocusVisualStyle is not applied when focus is moved with the mouse ??

Tony B

Sorry, I thought I replied to this -- apparently, only in my mind :-)

Anyway, to answer your question: Yes - clicking a button with the mouse WILL cause it to receive focus. In fact, you don't even have to click it -- simply press the mouse button down over the button and then slide the mouse off the button and let go. The button will retain the focus but the click event will not fire (since it is triggered by MouseUp when then cursor is within the bounds of the button).

I'm simply not buying the "desried behavior" on this one. This would be useless (and is) if it only works based on HOW you get the focus to move. What about pens, tablets and other input devices. The architecture of WPF is clearly designed to divorce itself from individual input hardware.





Re: Windows Presentation Foundation (WPF) FocusVisualStyle is not applied when focus is moved with the mouse ??

sharon9999999

Hi - what about a list box that has a default "placeholder" focus rectangle when the list does not have focus, the focus rectangle is a lighter grey. I want this gone completely. what is the property to fix that




Re: Windows Presentation Foundation (WPF) FocusVisualStyle is not applied when focus is moved with the mouse ??

norpe

Yi-Lun Luo - MSFT wrote:

Hello, this is the desired behavior. FocusVisualStyle only applies to the Control when it is focused via keyboard navigation. Try to open a Win32 dialog with more than one Control. If you simply click on a Button, will a dashed border appear ItĄŻll only appear when you use keyboard to focus it. If you need a different appearance for your control when it is mouse focused, you should use a Trigger for IsFocused property in your normal style.



I'm a bit confused by this behavior and how it's supposed to work.

If you start the Run-dialog in Vista the dashed border appears if you click a button and moves the mouse outside the button before relasing it. Try the same in the Properties-dialog and the dashed border do not appear. If you press tab once in the Properties-dialog and then click on a button with the mouse the dashed border do appear.

The FocusVisualStyle behavior in WPF do not seem to be consistent with Vista In WPF you never get the dashed border when clicking buttons with mouse as you get in Vista.

I would like to use FocusVisualStyle in our application but we need to show this when focus is set using the mouse or from code as well. Currently we use property-triggers but the FocusVisualStyle is a more elegant solution.

Is there any way to trigger a FocusVisualStyle to be displayed from a property-trigger when focus is set from code or using the mouse