Oleg Sh
Oleg Sh

Reputation: 9013

WPF - positioning with dynamically canvas

I have the following code:

<Grid>
    <Canvas Grid.Row="0" x:Name="drawingSurface" Background="White" ClipToBounds="True"
            MouseLeftButtonDown="drawingSurface_MouseLeftButtonDown"
            MouseLeftButtonUp="drawingSurface_MouseLeftButtonUp" 
            MouseMove="drawingSurface_MouseMove">
    </Canvas>
    <Grid Name="pnlProperties" Visibility="Hidden"/>
</Grid>

After starting this window, the user selects his interested area (I catch MouseMove, MouseLeftButtonDown, MouseLeftButtonUp).

Then I want to show the panel pnlProperties under the selected area in the left corner (in my interested coordinates).

How can I do it?

Upvotes: 0

Views: 330

Answers (1)

Erti-Chris Eelmaa
Erti-Chris Eelmaa

Reputation: 26268

Put the Grid into the Canvas, and then set the coordinates for the Grid, using:

 YourCanvas.SetLeft(pnlProperties, MOUSE.X)
 YourCanvas.SetTop(pnlProperties, MOUSE.Y);

Upvotes: 1

Related Questions