使用Silverlight可调整大小和可移动的矩形 [英] Resizable and Movable Rectangle using the Silverlight

查看:105
本文介绍了使用Silverlight可调整大小和可移动的矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <  画布    x:名称  =  cvsBurstImage     MouseLeftButtonDown   =  cvsBurstImage_MouseLeftButtonDown   样式  =  {StaticResource BurstCanvasStyle} >  
< Viewbox x:名称 = vbBurstImage 样式 = {StaticResource ViewboxCanvasStyle} >
< 图片 x:名称 = imgBurstImage 来源 = ../ Assets / Images / default_burst_image.png ImageFailed = imgBurstImage_ImageFailed / >
< / Viewbox >
< / Canvas >







我面临一个奇怪的问题,我需要在画布上绘制矩形并制作它们可以调整大小以及可移动(将它们放在画布中的任何位置)。



我通过画布的鼠标事件实现了这一点;



private void Canvas_MouseLeftButtonDown(object sender,MouseButtonEventArgs e){}

private void Canvas_MouseMove(object sender,MouseEventArgs e){}

private void Canvas_MouseLeftButtonUp (对象发送者,MouseButtonEventArgs e){}



解释;在MouseLeftButtonDown上,我开始捕获鼠标坐标并继续使用鼠标移动(使用这些坐标创建高度和宽度),在MouseLeftButtonUp上,我停止监听鼠标并在画布上将这些坐标绘制为Rectangle,并将此矩形作为子元素添加到画布。



我还需要Rectangle Re-sizable和Movable功能。

你能否告诉我如何实现Rectangle Re-sizable和Movable功能。?





谢谢....

解决方案

使用鼠标事件不是在Silverlight中移动矩形的最佳方法。

我建议你使用线性动画 - 例如 http://msdn.microsoft.com/en-us/library/ cc189066%28v = vs.95%29.aspx [ ^ ]。


正如我所说,您可能非常接近,只需要应用场景的逻辑或调试你的代码。从你的话来说,我可以看出你的方法是完全正确的,我看不到你的代码来找出缺陷的位置。



唯一有用的信息您可能已经错过了在WPF中为您开发的可视层中使用命中测试功能的可能性。请阅读: http://msdn.microsoft.com/en- us / library / ms752097%28v = vs.110%29.aspx [ ^ ]。



-SA

<Canvas x:Name="cvsBurstImage" MouseLeftButtonDown="cvsBurstImage_MouseLeftButtonDown" Style="{StaticResource BurstCanvasStyle}">
   <Viewbox x:Name="vbBurstImage" Style="{StaticResource ViewboxCanvasStyle}">
            <Image x:Name="imgBurstImage" Source="../Assets/Images/default_burst_image.png" ImageFailed="imgBurstImage_ImageFailed"/>
   </Viewbox>
</Canvas>




I am facing a strange problem where i need to draw rectangles on a canvas and make them resizable as well as as moveable (place them anywhere in canvas).

I have achieved this via mouse events of canvas;

private void Canvas_MouseLeftButtonDown(object sender,MouseButtonEventArgs e) {}
private void Canvas_MouseMove(object sender, MouseEventArgs e) {}
private void Canvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) {}

Explanation; On MouseLeftButtonDown, i start capturing mouse cordinates and continue doing so with mouse move (make height and width with these cordinates), on MouseLeftButtonUp i stop listening to mouse and draw these cordinates as Rectangle on canvas and add this rectangle to canvas as child element.

I Also need the Rectangle Re-sizable and Movable functionalities.
Can u please provide me how to achieve the Rectangle Re-sizable and Movable functionalities.?


Thanks....

解决方案

Using mouse events is not the best way to move a rectangle in Silverlight.
I suggest you use linear animations - e.g. http://msdn.microsoft.com/en-us/library/cc189066%28v=vs.95%29.aspx[^].


As I say, you are probably quite close and only need to apply the logic of your scenarios or debug your code. From your words, I can see that your approach is quite correct, and I cannot see your code to find out where is the flaw.

The only useful piece of information you might have missed is the possibility to use hit testing capabilities in visual layer already developed for you in WPF. Please read this: http://msdn.microsoft.com/en-us/library/ms752097%28v=vs.110%29.aspx[^].

—SA


这篇关于使用Silverlight可调整大小和可移动的矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆