WPF - 使用动态画布定位

时间:2013-05-17 11:09:07

标签: wpf canvas position

我有以下代码:

<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>

启动此窗口后,用户选择他感兴趣的区域(我抓住MouseMoveMouseLeftButtonDownMouseLeftButtonUp。)

然后我想在左角的所选区域下显示面板pnlProperties(在我感兴趣的坐标中)。

我该怎么做?

1 个答案:

答案 0 :(得分:1)

Grid放入Canvas,然后设置Grid的坐标,使用:

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