I am using Surface 2.0 SDK and my application uses dynamically created custom controls which consist of a ScatterViewItem which holds a Grid with a Menu inside each column.
When initiating a drag&drop motion on any area inside the ScatterViewItem including the Grid, or the margins around the Menu, the ScatterViewItem is being dragged along nicely together with its contents.
However, when trying to initiate such a motion anywhere inside the Menu control, nothing happens. It seems like the necessary events are being swallowed by it.
I have tried extending the Menu class to create a custom control and use a RoutedEvent to handle captured mouse clicks within the ScatterViewItem, but can't quite find a way to seamlessly handle drag events and pass them on to the parent ScatterViewItem
Can anyone share some knowledge on how to implement this?
Related
Gmap.net wpf control has markers as item source. any idea how to add button control to it. i.e. transparent zoom in and out button?
Your best bet is to position the respective buttons above the map control, and use them to control the parameters of the map control.
Edit: I wouldn't try to include buttons to the control itself, easiest thing to do in WPF is to place custom UIContols as buttons on a layer above the map control, e.g. within a Grid layout. And then simply have button commands trigger the desired map functionalities such as zoom etc. Need a sample to get an idea? Or is my suggestion way from what you try to achieve?
I have displayed an image in a Windows form. The user can draw a rectangle on top of this. When the user releases the mouse after drawing the image, I need to display a few buttons, similarly to showing a tooltip.
So far, I have:
Created a new WinForm named Toolbar
Removed titlebar
Added tooltip control on the WinForm
Added 4 buttons
Being an ASP.NET web developer I perceive the following items as missing:
Handle MouseUp event
Get co-ordinates of the mouse release location (say x1, y1)
Render my Toolbar Winform with top position as (x1, y1)
Let the respective buttons handle their responsibilities in their event handlers
Can you please help me validate my approach and show some pointers for the code?
You can use ContextMenuStrip (info from MSDN)
With 4 Items and just show it on MouseUp event with:
contextMenuStrip1.Show(Cursor.Position);
Two approaches:
This. You create a Popup form, which will be automatically hidden similar to popup menu and can host controls (buttons).
Display (draw) buttons inside your control, on top of its content (on top of graphics which you drawn), process mouse clicks, perform operations accordingly. Most difficult will be to draw nice looking buttons, to example, by using VisualStyleRenderer (xp-style).
Do not aks big question (containing many small one), rather try something, if it doesn't work or you are not satisfied with results, then come here and ask question (while also telling what you are trying to do). This way you will get help very quickly.
I'm finding it extremely difficult to drag and drop any control (and I plan to allow ANY control) to be dragged and dropped in my app without having a Drop target or whatever. I just want to be able to drag any control from, say, here... to "over there somewhere". But this doesn't seem possible. Is this possible? You can implement drag and drop in WinForms with just a few lines of code, how do we have this same drag and drop support in WPF?
What you're describing in the question and the clarifying comments is more about repositioning elements than dragging and dropping.
This type of activity is fairly easy in WPF, the only consideration is the Layout Panel that houses the elements. Because WPF tries to provide more structure around Layout (with Grids, StackPanels, etc.) you need a panel that will allow for free-form positioning of elements. This calls for the Canvas.
So if you have a Canvas with elements on it (positioned with the Canvas.Left and Canvas.Top for example), you can use the MouseDown, MouseMove and MouseUp to allow users to drag/reposition elements across the canvas.
I am making a simple chat box control. Its just a hobby project to learn. I want to make my own control like below :
I have learnt how to paint graphics and text onto a custom control surface inheriting from control using OnPaint. But problem is I want this control to have the elements in the screenshot, most importantly to be able to infinitly scroll. Had a try googling but didnt find any answer.
Also because its painted, I probably wont be able to differentiate between the different users, or the speech bubbles as they are all the same to the control.
But is there a way to know the user is clicking on a certain bubble, or certain user? And the other question was how to make it scrollable?
Many thanks in advance.
If you want to make it scrollable, you should try to make each comment a separate panel & add that panel to your control.
Then set the autosize property of your control to true (you will need to make your control a panel, inheriting control doesn't have autosize property).
For the clicking on the bubbles, I suggest again to make each bubble a custom control & then add it to the panel (the panel inside your main panel), then just use the MouseEnter event.
I have a custom Canvas control (inherited from Canvas) overlaid over a large area of User Controls. The idea is to draw paths between user controls (i.e. connector lines).
To capture mouse movement, I call Mouse.Capture(theCanvas) on MouseDown. This works beautifully, but the user controls under the canvas obviously no longer receive mouse events. Mouse.DirectlyOver always shows the canvas, so I can't really fake it by peeking at the current position and seeing which user control it's over.
So, I still need the Canvas for drawing paths, but how can I solve this one of the following ways:
Peek under the Canvas and see what the topmost control is right under it?
Get this MouseDown -> Track MouseMoves -> MouseUp workflow to work on the canvas without mouse captures?
Any other ideas welcome...
I'd agree that those are your two options. If you want to only forward some clicks to your usercontrols, then go with option 1, and hit test the controls under the canvas.
If you need your usercontrols to behave as though there is nothing covering them (textboxes, buttons etc), then i'd recommend using the PreviewMouseMove event on the user control's parent, as this can pick up and optionally "handle" events before the controls get at the event, but it won't block the event if you don't set handled to true