I am new to Silverlight and I am looking to create a StackPanel that scrolls by dragging it up or down, similarly to how PDF readers work. I did not know if there was anything built in or if I would have to create my own based on mouse down and up.
Hm, just catch MouseMove when LMB is down and change scrolling offset by horizontal difference between last and current points.
Related
I have a WPF app with a canvas inside a ScrollViewer. On the canvas I have some rectangles that I drag along a timeline (left-right). This works fine with a mouse, but on a touch screen I get weird behavior if the canvas is wider than the main form. First, when you begin to drag the rectangle, the canvas pans until it has scrolled to the limit, then the rectangle starts to move. I doesn't do this when using a mouse.
Another strange this is that if I pan/drag the canvas (using touch) to the limit of the scrollviewer, the main form compresses by 20-50 pixels on the side opposite of the pan direction. It springs back to shape as soon as you stop dragging. What's going on here and how do I disable this?
It seems that this has to do with ManipulationBoundaryFeedback, but I don't understand exactly how...
EDIT:
So I was able to get a little further by setting the scrollviewer panningmode to PanningMode.None in the rectangle TouchDown handler and then setting it back to PanningMode.Both in the TouchUp handler. This solved the problem of the canvas panning to the limit before the rectangle would move.
Well, I finally got my app to work with touch. As I mentioned above, setting the PanningMode to None on the TouchDown event eliminated the problem with the ScrollViewer. Setting it back to Both in the TouchUp event re-enabled it. What this means is that I can't drag the rectangle past the point where the ScrollViewer would start panning, but in my case this was not a problem.
I also had some issues with the MouseLeftButtonDown event firing during the TouchMove event so I removed it during TouchDown
-= new MouseButtonEventHandler(drag_start)
and re-added it back during TouchUp to eliminate the glitchy behavior.
+= new MouseButtonEventHandler(drag_start)
Maybe this will help someone in the future...
I have created a usercontrol that is essentially a text editor (using Graphics.Drawstring in OnPaint).
I have set AutoScroll = true, and AutoScrollMinSize values appropriately. Everything is working how it should...
EXCEPT, i would like the control to scroll itself WHILST I am currently scrolling (i.e. click and drag the scroll bar... and whilst it is being dragged the control should be scrolling the entire time). At the moment it only scrolls when the scroll bar is released (mouse up).
I have tried implementing _Scroll and invalidating the control, but that just makes it flicker uncontrollably.
I cannot find any examples online for this, due to it being difficult to describe!
Can anyone point me in the right direction please?
Control.Invalidate() will make something flicker badly. I faced this problem drawing cross-hairs over a mouse position on a PictureBox drawing a line chart before. The trick is to use (and I cant remember which one is best to come first)
Control.Update();
Control.Refresh();
in the Scroll event. Depending on what else you are drawing in the Control and how you are drawing it this may be better for you. Also this is tested on PictureBox, Control may be another matter.
I'm currently using the Surface SDK 1.0 in Blend and VS2008, and I've encountered a problem: I use a scatterview over the whole screen. I also have a grid in the middle of the screen. The panel in the middle is quite annoying because my scatterviewitems can easily get lost BEHIND the grid, and since the grid is locked in position, there is no way for me to retrieve them.
It would be desireable to add "walls" around the grid, so that my scatterviewitems would bounce off it, as it does at the edges of the scatterview.
How can I solve this problem?
Just hook up to "ScatterManipulationCompleted" and check if the item is under your grid. If yes start a Storyboard which moves the Center of your ScatterViewItem back out of the grids background.
Also take a look at the surface community forums, there are a lot posts regarding ScatterViewItem and collision detection.
I've got a container, say a Grid. It has two containers, say StackPanels.
StackPanel #1 has some rectangles. What's the best way to enable a user to drag a rectangle and drop it in the StackPanel #2 (and have that rectangle be a child of StackPanel #2).
I've got the drag bit sussed - the only thing that's unclear is whether to actually use containers or just handle all the rectangles manually in a straight canvas.
As far as the logic behind actually moving the items goes, a StackPanel as a container is just fine. If you want to preview the item whilst it's being dragged, you can implement an Adorner that displays the Visual whilst it is being dragged.
I am developing a form in .NET Compact Framework, which hosts a variable number of controls. Every control should have the same width as the form. When there are only a few controls, no vertical scrollbar appears. When there are more controls than they can fit in one form, a vertical scrollbar appears. The width of the controls should then be modified, so that no horizontal scrollbar appears.
What is the best way to achieve this? I am interested in a solution that will work in all platforms/screen sizes and that can support screen orientation changes.
If I get this right, at one point, both a vertical and horizontal scrollbar appear, and you want only the vertical scrollbar? Doesn't setting the Anchor of each control to "Top|Left|Right" solve this problem automatically?
If every control is to be the same width as the form, why not just Dock every control to Top (or Bottom)? It'll take care of the resizing for you then. It might not look very attractive however, so I suggest adding in some empty Panels (docked the same way) to be used as vertical spacers.
I did some quick testing, and it seems, when you add controls, the panel raises the resize event when the added control tiggers the scollbars to go visible. The annoying part is here that the resize event is triggered a couple of times during startup :(
But knowing the compact framework, this might be your best shot at handling this.
Normally on the full framework you could if the DisplayRectangle is bigger than the size of the panel, but no such thing exists on the cf.
Hope this is of some help, I'll see if I can find anything more in the morning.