我正在尝试在Windows Phone 7.1中捕获签名。
我可以在屏幕上绘图但我不能将绘图区域限制为InkPresenter控件,除非在mousemove事件中添加一些处理。
如何使用XAML限制绘图区域,或者这是不可能的?
XAML代码
<InkPresenter Name="inkTest" Background="White" MinHeight="180" MinWidth="250" />
代码背后
private Stroke _currentStroke;
private void inkTest_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
_currentStroke = null;
}
private void inkTest_MouseMove(object sender, MouseEventArgs e)
{
if (_currentStroke == null) return;
//HACK: want to set this in XAML
var position = e.GetPosition(inkTest);
if (position.X <= inkTest.ActualWidth &&
position.Y <= inkTest.ActualHeight)
_currentStroke.StylusPoints.Add(GetStylusPoint(position));
}
private void inkTest_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
inkTest.CaptureMouse();
_currentStroke = new Stroke();
_currentStroke.StylusPoints.Add(GetStylusPoint(e.GetPosition(inkTest)));
_currentStroke.DrawingAttributes.Color = Colors.Blue;
inkTest.Strokes.Add(_currentStroke);
}
private StylusPoint GetStylusPoint(Point position)
{
return new StylusPoint(position.X, position.Y);
}
答案 0 :(得分:2)
未经测试,但请尝试裁剪:
<InkPresenter Name="inkTest" Background="White" MinHeight="180" MinWidth="250">
<InkPresenter.Clip>
<RectangleGeometry Rect="0,0,180,250"/>
</InkPresenter.Clip>
</InkPresenter>
如果您需要不同的形状,请将RectangleGeometry
的边界更改为您想要的边界(或更改RectangleGeometry
元素本身。)