场景
我在网格中有几个对象。我在他们的操作增量事件中翻译它们。对象似乎卡在用户的指针下方。它有效,看起来像这样:
ellipse.ManipulationDelta += (s, e) =>
{
var transform = ellipse.RenderTransform as CompositeTransform;
transform.TranslateX = e.Cumulative.Translation.X;
transform.TranslateY = e.Cumulative.Translation.Y;
}
每个可移动对象都有一个椭圆边界,不应将其拖动到该边界之外。这个值很容易计算。像这样的东西:
ellipse.ManipulationDelta += (s, e) =>
{
var boundary = new Ellipse { Height = 50, Width = 100 };
var transform = ellipse.RenderTransform as CompositeTransform;
transform.TranslateX = e.Cumulative.Translation.X;
transform.TranslateY = e.Cumulative.Translation.Y;
};
要求
如果请求的点在椭圆边界之外,我想实现某种不会转换元素的逻辑。
一些东西,也许是这样的:
ellipse.ManipulationDelta += (s, e) =>
{
var boundary = new Ellipse { Height = 50, Width = 100 };
var point = DeterminePoint(boundary, e.Cumulative.Translation);
var transform = ellipse.RenderTransform as CompositeTransform;
transform.TranslateX = point.X;
transform.TranslateY = point.Y;
};
Point DeterminePoint(Ellipse boundary, Point target) { /* TODO */ }
我可以轻松编写代码以将逻辑限制为矩形。但是矩形不是必需的,椭圆是。上面代码中的TODO
部分是这个问题的核心。
先感谢您。