Razlo3p
Razlo3p

Reputation: 487

Moving Control over a ScrollViewer

I'm developing a small WPF application which uses a ScrollViewer to show an Image in a Window. I have generated the window and all his relative code (I will show it if needed but I think is not usefull for the point of this question) programmatically.

The question/ how to is the following. I have to show/hide (pressing a button) a control (basically a InkCanvas) over the image contained in the ScrollViewer. Except the part oh show/hide is pretty simple to use the button event) which is the best way to add a control (and which type of control/container) at the Window forcing him to be over the ScrollViewer and then be able to move around dragging it?

I'm relatively new to WPF I used a lot of WinForms (I can do this in WinForms but WPF is a new world for me).

Thanks in advance!

Upvotes: 1

Views: 124

Answers (1)

Pragmateek
Pragmateek

Reputation: 13354

As for the container you should use a Grid which will center and put on top of each other the controls in a same cell.

As for drag and drop if you want to implement it yourself I've provided a minimal implementation here: https://stackoverflow.com/a/17014906/145757

Otherwise you can use the MouseDragElementBehavior behavior provided by Blend.

Here is a tutorial that demonstrates its usage from Blend itself: http://www.c-sharpcorner.com/uploadfile/nipuntomar/expression-blend-4-behaviors/

But you can use it without Blend by importing the Blend libraries and using it from your XAML with something like:

<InkCanvas ...>
    <interactivity:Interaction.Behaviors>
        <blendbehaviors:MouseDragElementBehavior />
    </interactivity:Interaction.Behaviors>
</InkCanvas>

with interactivity and blendbehaviors being mapped to the Blend namespaces.

Upvotes: 2

Related Questions