I am writing a control in WPF that draws a shape on a form and then draws dimensions of this shape. These dimensions are editable so they are shown in a text box. When the user changes a dimension in a text box the shape is updated.
I am updating the shape when the textbox showing the dimension loses focus i.e. as soon as the text box loses the focus the shape and all the dimensions are redrawn. A text box loses focus in one of two ways - either when user presses tab key or when user clicks in another control outside the text box.
My problem is that when user presses tab key or clicks somewhere else outside the text box the whole control is redrawn and the focus is not set to the next control where it should be. This is really annoying because tabs stop working altogether and to set a focus using mouse the user has to click twice. Is there a way around this?
An image of my control is shown below
alt text http://img223.imageshack.us/img223/9496/cavity.png
It seems that you want to manage the tab order yourself in this window and to do that, I'd think you would subscribe to the GotKeyboardFocus and LostKeyboardFocus events on those edit fields and then drive focus to the appropriate location if you're not happy with where focus has gone.
Related
If I catch mouse move/mouse button down events in one control, how do I route the caught event to another control?
In MSDIN documentation I found WPF UIElement.RaiseEvent but it seems it doesn't exist in Silverlight.
The reason for this question is the following issue.
I have an application where user is able to pick a control on the screen to retrieve control's ID (a custom property). While user picks a control, I don't want default actions of the control to be triggered - no button clicks, no text highlighting, no link navigation etc. That's why when entering the "picking mode", I put a transparent overlay over my application and after user clicks on it I find the element behind the overlay, get its ID and remove the overlay.
This approach is working fine except one scenario when there is a scroll viewer on the screen and user might want to pick an element which is scrolled out of view. Thus when picking elements, user at first clicks on a scrollbar to scroll the required element into view, but the scrollbar doesn't work because its behind the overlay.
Currently I have working code which detects if the element under mouse cursor (and behind the overlay) is a scrollbar instance, and thus I ignore it for my picking process - my application doesn't require picking scrollbars. But how do I pass the mouse event from the overlay to the scrollbar behind?
The short answer is, you can't route the mouse events.
But what you can do is: as long as the mouse is hovered over a Scrollbar you can set the IsHitTestVisible property of your mouseClick catcher overlay to false. The click will just go through it. Or can you only detect the Scrollbar the moment the user clicks?
I have a WPF datagrid (4.0) with a custom column (derived from DataGridTextColumn).
In GenerateEditingElement I create a custom textbox control (with an additional button) and like to set the cursor into it so that the user can directly start editing.
The closest I get is that the caret is shown but is not blinking and I need an additional click to start editing.
All other stuff (binding, ...) is working nicely
Any ideas?
Since the caret is shown, but not blinking, then I am guessing your control has Logical Focus, but not Keyboard Focus.
How are you setting the control as Focused?
myControl.Focus(); will give the control logical focus, but it won't respond to keyboard events because it doesn't have Keyboard focus. To give an element KeyboardFocus, use
Keyboard.Focus(myControl);
This is because WPF allows you to define multiple Focus Scopes, and each scope can have it's own focused element, however only one control in the entire application can have Keyboard Focus
I want to add the menubar to TextBox control in Silverlight 4. (I will create a new reusable control.) The menubar will consists of a few image buttons. The idea is that it will normally stay hidden and will show up only when the user puts his/her mouse cursor to the TextBox area. If used in a multiline textbox, whole menubar can fit inside it, this should be easy. (I hope. :-))
But how to solve situation when TextBox is in single line mode? I'd like to put the menubar above the TextBox. But I don't have a clue how to do it. Can somebody help? I need to let all other controls in a form to stay in their positions, and only add my menubar above my textbox. (So the menubar will NOT hide the textbox. Instead, it will hide other controls residing right above the textbox.) It should work in all arrangements of form, like Grid, StackPanel, Canvas etc. In the fact it would be similar to a classic right-click context menu, but not modal. (Right-click context menu is modal, i.e. while it is shown you cannot use other controls, and it automatically hides when you click anywhere else. I want my menubar to stay visible as long as user heeps mouse cursor over the textbox or the menubar.)
Example: Coordinates of textbox are top=100,left=20,bottom=115,right=120. So my menubar's coordinates should be bottom=100,left=20, right & top are based on size of menubar.
If many textboxes will be used on a single page, each single one should have its own menubar. (Of course.)
You can create your own control (custom control or UserControl, whichever you like should work) which has the TextBox, and the visual for the menu bar.
If the TextBox is single-line, you could display the menu bar in a Popup which you position just above the TextBox whenever the mouse is over it.
If the TextBox is multi-line, you'd simply use a StackPanel or Grid or whatever to do layout like normal, if I am understanding what you want.
No coding required if you use this menu:
http://sl4popupmenu.codeplex.com
To achieve this behavior you will need to set its IsPinned property to true.
I have a grid, and in the grid I am setting my first element to be focused:
<Grid FocusManager.FocusedElement="{Binding ElementName=companyNameField}">
When the window opens, the correct control is focused.
But if I tab through the whole form, when the above focused field, should have the focus, there is no cursor evident anywhere on the window.
If I hit tab once more, it selects the control after the control that should be selected.
If I completely remove the focumanager attributes from my grid, I am correctly tabbing trough all my controls in the correct order.
Even stranger, if i leave in the focusmanager attributes and first click on the first text box and then focus through the entire form, then it selects my text box like any other control.
If you have any Ideas, I would love some help.
Thanks
I have had this happen to me, when I had some focus code in the code-behind fighting with the FocusManager. Mine was hidden in the Load of a nested UserControl, so I didn't notice it.
I have a text box that has spell check enabled. It is inside a popup. This enables me to edit multi line text in a datagrid, when the text is being edited the text box it is in grows over the top of the grid instead of resizing the height of the row.
The problem is that when the red squiggly lines appear to indicate a spelling mistake i cant right click on them, because when i do the popup closes.
I have tried Popup.StaysOpen but to no avail. any ideas?
Have you tried this outside the context of the DataGrid? I have a hunch that it is most likely the DataGrid detecting that focus has been lost and is automatically applying your edits, changing the template for the cell and thus closing your Popup.