2012-12-11 94 views
1

我想在windows phone 7.1中捕獲一個簽名。剪輯InkPresenter到繪圖區域

我可以在屏幕上繪圖,但我無法將繪圖區域限制爲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); 
} 

回答

2

未經檢驗的,但嘗試剪裁:

<InkPresenter Name="inkTest" Background="White" MinHeight="180" MinWidth="250"> 
    <InkPresenter.Clip> 
     <RectangleGeometry Rect="0,0,180,250"/> 
    </InkPresenter.Clip> 
</InkPresenter> 

更改的RectangleGeometry的邊界到你想要的(或者如果你需要不同的形狀,改變RectangleGeometry元素本身)。

+0

不客氣:) – keyboardP