How to position a menubar above TextBox in Silverlight? - silverlight

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.

Related

WinForms : how to add toolStrip to a form already divided into left/right panes using a SplitContainer control

My form is divided up into left and right panes, and the right pane is split into upper and lower panes:
AAAABBBB
AAAACCCC
There's a menu-strip at the top, below the title-bar and a status bar at the bottom:
menuStrip
AAAABBBB
AAAACCCC
status
Now I would like to add a toolStrip below the menuStrip. But when I do so, the toolStrip obscures the topmost content of the panes created using the splitContainer control. The Dock for the toolStrip = Top.
What am I doing wrong that the toolStrip doesn't simply get inserted between the menuStrip and the splitContainer control, pushing the splitContainer control down, so to speak?
You have to play with the BringToFront and SendToBack context menu items of those controls in the designer.
Drop the toolstrip container onto the form, then open the Document Outline window to re-arrange the controls into the correct hierarchy.
There are 2 simple ways of doing that:
Method 1
Open Document Outline window: View\Other windows\Document outline. Use buttons to place your control in the correct place
Method 2
Notice, that the current control in designer form is marked with some kind of focus rectangle.
You can easily navigate through current control parents using Esc key: once pressed, it can be used to go exactly one parent up in hierarchy.
Knowing the above just place your control in any place, cut it and then past it in the correct container. Repeat the step for any other control which is not in a good position
When you need to change the order of control in the same container use Bring To Front and Bring To Back from context menu
You have to set the splitcontainer's dock to none and instead use its anchor settings

WPF Adorner Overlay Problem

I am trying to achieve functionality similar to that of a Popup, without using a Popup, but instead adorning my ContentControl with a basic adorner. Basically, I want the ContentControl to have an "overlay" effect, whereby it is the topmost object, above all other elements - similiar to that of the Popup control.
Here is the problem that I am running into, and I am hoping that someone can point out where I am going wrong:
I have a stand grid with two row definitions. The first row contains a UI element - for example, a rectangle. The second row contains a custom control that I have developed to emulate the functionality of a "drawer" sliding out. Basically, when I click on button, I am going to animate a TranslateTransform to "slide" my ContentControl "up". This works fine - except that it gets cropped underneath the rectange in the first row of the grid. If I remove the row definitions in the grid, then when the desired behavior is achieved - the ContentControl is moved "up" and partially "on top" of the rectangle. The rectangle is merely a place holder for what I am trying to achieve. I basically want to have a drawer type control that can slide out and be on top of all other controls.
I am somewhat new to using the Adorner class, so, I am hoping that someone can please point out where I am going wrong.
Thanks.
Chris
Change the parent of the adorner to the full grid, and not just your control. If you put a control in a grid row, and set the adorner to adorn the control, it will usually be clipped to that row because the control is.

WPF FocusManager interferring with focus

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.

How do I create a WPF Dropdown panel

I'd like to create a dropdown panel in WPF the acts like a ComboBox/Expander hybrid. I'm currently using an Expander but it pushes the the controls underneath it down when it expands.
I simply want it to act like a ComboBox and overlay it's dropdown. I've looked at using Popups but they don't move with the underlying window when it's moved.
So, I've concluded that the closest control to my needs is a ComboBox which allows me to put a Grid or StackPanel into its dropdown area.
Any ideas how to achieve this?
I am not exactly sure what you want to do:
But the layout depends very much on the parent control. If your controls are in a Stackpanel all controls will be moved if a control expands or changes its size. If you use a Canvas you can align controls on top of each other.
Also Adorner are useful when you want overlay something above something else.
You can change the appearance of the ComboxBox and you can put a grid or anything else inside it. Have a closer look at ItemTemplate.

Binding a Popup to another control's relative screen position

I'm writing an XBAP with a complex Popup (Canvas Z-index of 99 with a grid on it...) that I would like to "attach" to the button that opens it and follow that button around wherever it goes on the screen. For example, if the button is in a ListBox or an XamDataGrid I would like the popup to follow the button as it scrolls through. If it is beneath an Expander I want it to stay attached to the button when the expander forces it to move, etc.
Any Ideas?
When using a Popup, neither PlacementTarget nor CustomPopupPlacementCallback is used after the popup has originally appeared. So any use of these properties will not allow the popup to track the button as it moves.
Several ways occur to me of achieving what you desire:
Attach a custom Adorner to the button and put the popup inside it. Disadvantage: Popup is not connected to Button or surrounding elements, so it won't inherit properties & DataContext from them.
Attach a custom Adorner to the button. This adorner will get measure and arrange calls when the button moves relative to the AdornerLayer, allowing you to manually update the Popup position. As long as your AdornerDecorator doesn't move relative to your Window (eg if it is the direct child of the Window), you can easily detect the AdornerLayer being moved by monitoring changes to Window size. Disadvantage: Complex to code & get right.
Don't use a Popup at all. Instead wrap the button in a <Grid> alongside a <Canvas> with zero width and height and the desired position. Inside the <Canvas> add the UserControl for the popup with an appropriate ZIndex. It will extend past the edge f the Canvas, which is just fine in WPF. Instead of using a Popup control just control the visibility of the UserControl. Disadvantage: Will not really be totally on top of all other objects, can't extend off edge of window (may not be an issue for XBAP, though).
I'm not sure if it will auto-update for you or not, but the PlacementTarget property allows you to specify a control to position the popup relative to. If that doesn't work, then maybe CustomPopupPlacementCallback will do the trick?

Resources