I have an ellipse within canvas in my windows phone application and I need to implement tap&drag behavior for it. I use ManipulationDelta event for that.
The problem is that ellipse is small and it is quite hard to touch it precisely and trigger manipulation.
So the question is how can I increase the area around ellipse which is responsible handling user touch and triggering manipulation?
you can take another bigger ellipse which is transparent and cannot be seen, keep the smaller ellipse on it, and then add the manipulation event on the bigger ellipse, what ever code you write, write it for the bigger one and your task is done.
You've got multiple options, like Hatim's suggestion of a larger Ellipse. Or another shape like a Rectangle so the corner could get hit better etc. However you'll have to embed them both in a parent object anyway so they share the events and move together. So might as well just use the parent object. Could also just use MouseDragElementBehavior instead of messing with the ManipulationDelta if you wanted. Something like;
<Canvas>
<Grid>
<MouseDragElementBehavior/>
<Ellipse/>
</Grid>
</Canvas>
Then you could use a Margin on the Ellipse or set the size of the parent Grid or a number of options to accommodate the requirements. Hope this helps.
Related
I am trying to make a WPF application in which there is a drag able toolbar on the screen through which user can select different type of tools and use it on canvas. Also can someone tell me how to make a transparent canvas. A good example would be from this picture in which there is drag able toolbar on right side of the picture. And the user can also work on any window he wants. I am new to WPF and I am trying to find a solution to my problem for quite a while now. Can someone guide me in the right direction...
Background DP default value is null. When a Background is set to null the displayed Color is White and mouse interactions don't work. You need to set Canvas's, ListBox's and ListBoxItem's Background to Transparent to see the Background of the Parent Control
<Canvas Background="Transparent"/>
Rather than a toolbar, think of that as a window.
I would take a look at avalondock.
A transparent canvas:
<Canvas Background="Transparent"
As an aside, this is a couple of steps on from wpf beginner level.
If you take a look at this:
https://imgur.com/4n7vH8k
The user is designing a game scenario. They drag units out the panel on the left ( it's a treeview ) onto the canvas on the right. Only this is not just a plain canvas, it's an itemscontrol with a canvas as the itemspresenter. That allows me to template out the units from a collection of unit view models. It's using the mvvm pattern.
If you've not come across this technique it's a bit strange. Here's a couple of samples to take a look at which templates out different viewmodels into different UI objects. https://1drv.ms/u/s!AmPvL3r385QhgooJ94uO6PopIDs4lQ
https://1drv.ms/u/s!AmPvL3r385QhgooLcGrZOSwFswa-Dg
The datatype is used to decide what you get in the view for what viewmodel.
You have a bit of a complication in that you decided you want a dockable panel usable in multiple windows. Maybe that's not a must have.
Drag drop in my app isn't actually drag drop and relies on an odd aspect of a canvas. They don't clip, so you can add something to a canvas but have it positioned off the canvas.
As you start dragging a unit, it's viewmodel is added to the collection bound to my units itemscontrol. That templates it into the canvas as a piece. I work out the location compared to the canvas, so it'll have a negative X aspect which I bind to Canvas.Left.
Each unit is inside a thumb. A thumb is the rectangle you drag up and down on or side to side on a slider. They are designed for dragging. This way dragging is smooth and I can easily have a unit under the cursor that's being dragged.
I am a not very good at C# yet so bear with me,
I am trying to create a program that can edit pictures of small sizes (16x16, 32x32, etc...), specifically Minecraft texture files. I need to create a drawing surface where I can display rectangles on. I want to use WPF rectangles because they are working for me so far. I tried putting them on a WPF Grid panel but creating a good size grid panel with 1 pixel wide rows and columns takes about thirty seconds and that's quite a lot of time. Any ideas are helpful.
I'm getting the feel that your direction might not be the most efficient.
Of course, it's quite possible to convert an image into a lot of rectangles, but it's really not efficient once you have a lot of pixels. (32x32 = 1024 rectangles.)
So, instead of going along with WPF rectangles, like you want to, I would urge you to reconsider. Instead, try to work with WriteableBitmap.
From your vague description, I assume you are writing a paint like program, where the user can select a color and draw with the mouse on the texture with that color. By binding the WriteableBitmap up to an Image tag, and adding an event listener to the MouseMove event, you can get the mouse position, and whether the left/right mouse button is pressed or not. Combine that with some math involving the x position and the ActualWidth, and the y position and ActualHeight, of the Image, you can find the pixel the mouse is over, and set the color of that pixel.
So basically, Rectangles are not your best bet. Especially if you try to make a 32x32 grid to contain them. Use WriteableBitmap.
I would suggest using something more lightweight like DrawingVisuals. Alternatively if you really just want to display the textures you can preprocess them and display the result as a normal Image.
I am facing a problem that have kind of already been asked here before, as far as I have seen.
I read most of these but didn't find the right answer.
This is what I need:
Complex shaped zone (i.e: countries, states..)
Having possibility to get events on it (especially mouse's)
Possibility to place some conrols in it (i.e: images, buttons)
I saw that some uses usercontrols, controltemplates.. But how should I do for that kind of shape ? Most of questions was for some basic mix of standard shapes.
(I saw with Blend that we can make path object with a pen, is there a way to use this to define the shape of a zone ?)
Thanks.
Create your own control and have its main container be a Canvas. Have the canvas background be transparent and then you can place all the controls you want on it. You can use a Polygon as your main shape inside the Canvas and place all the controls you want on the Canvas (but I guess for your purpose, you would want to make sure to not place them outside of the area covered by the polygon.
Let each object you use handle the mousedown event then you can individually drag them. When mousedown occurs, use the CaptureMouse() method on the object you clicked so that all dragging (on or off of the main window) will still be captured by the object you clicked. Make sure to call ReleaseMouse() in the mouseup event.
You can create as many instances of your control as you need. All with different shapes defined by the polygon each one contains. You can slap all of these objects on a single grid or canvas, and you're good to go.
You can use the PathPanel class that is provided in the Expression Blend SDK.
More information here
The scenario is that i want the user to create a shape in a small panel that opens (the added shape can later be placed on the canvas), but for a better reference, i want the user to be able to move the semi-transparent panel somewhere on the canvas and then draw with the accurate reference.
Please tell me:
Which panel type to use
How to make it moving by clicking the mouse on the move button (not the whole panel as dragging will be used for drawing lines) and move it around.
How to make it semi transparent.
How to make it appear and disappear (this should be pretty simple)
How to somehow limit its movement inside the canvas so it cannot move on the ribbon
And I really really hope there will be something built-in in WPF that i'll be able to use, and i will not have to do it the hard way i.e. create a rectangle, and do customized hit testing on it to allow the user to draw on top of that rectangle, make that rectangle transparent, and add graphics items for the buttons and controls on that rectangle "panel".
I am asking this because i have never seen such feature in any Windows application and i have no idea what to use for this purpose and how to implement it. The closest thing to what i want is in Adobe Acrobat Pro, which is the small preview of the page that appears when i double click with the middle mouse button. It doesn't move, nor it is transparent or can be drawn upon, but scale and shape wise i want something similar.
You should be able to place a second Canvas inside of your main canvas, and place whatever UserControl you'd like with your "view" inside of it.
You'll have to handle the mouse click/drag for moving it around yourself, but otherwise, it should be very straightforward.
I am using c# winforms to show an Image. The displaying of the image is done using a user control. Now I want to provide the user to draw lines, put other small images, write text etc over the image on an overlay control. How can I provide this functionality? If I use another user control to show the overlay control with transparent back, will that work?? any other solution will be welcome.
You might try approaching this with a canvas (Panel) that handles painting the image as the background and all the annotations/markup afterwards. This will make the foreground appear to be transparent. I expect you'll want to set Control.DoubleBuffer for performance.
You might experiment with setting the style ControlStyles.AllPaintingInWmPaint. Also, try overriding Control.OnPaintBackground and do nothing, and override Control.OnPaint and do all your painting inside there.
If performance is still unacceptable, pay close attention to the PaintEventArgs.ClipRect property. This is the only area you need to paint. The trick is figuring out which of your annotations/overlays intersect with this rectangle and painting them in the correct order.
Either this canvas or a higher level control will need to track mouse movement so you know where to draw the lines, paste images, etc.