2 回答

TA貢獻1829條經(jīng)驗 獲得超9個贊
這是給你的demo,希望對你有幫助。
XAML 頁面:
<Grid x:Name="rootGrid" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
</Grid>
后面的代碼:
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
rootGrid.PointerPressed += RootGrid_PointerPressed;
rootGrid.PointerMoved += RootGrid_PointerMoved;
rootGrid.PointerReleased += RootGrid_PointerReleased;
rootGrid.PointerExited += RootGrid_PointerExited;
}
int pointerId = -1;
Line curLine = null;
private void RootGrid_PointerExited(object sender, PointerRoutedEventArgs e)
{
OnComplete();
}
private void RootGrid_PointerReleased(object sender, PointerRoutedEventArgs e)
{
OnComplete();
}
private void OnComplete()
{
// reset pointerId so that other pointers may enter live rendering mode
pointerId = -1;
curLine = null;
}
private void RootGrid_PointerMoved(object sender, PointerRoutedEventArgs e)
{
var pointerPoint = e.GetCurrentPoint(rootGrid);
if (pointerId == (int)pointerPoint.PointerId)
{
curLine.X2 = pointerPoint.Position.X;
curLine.Y2 = pointerPoint.Position.Y;
curLine.Stroke = new SolidColorBrush(Colors.Red);
}
}
private void RootGrid_PointerPressed(object sender, PointerRoutedEventArgs e)
{
// Make sure no pointer is already drawing (we allow only one 'active' pointer at a time)
if (pointerId == -1)
{
var pointerPoint = e.GetCurrentPoint(rootGrid);
if (!pointerPoint.Properties.IsLeftButtonPressed)
return;
curLine = new Line();
var position = pointerPoint.Position;
curLine.X1 = pointerPoint.Position.X;
curLine.Y1 = pointerPoint.Position.Y;
curLine.StrokeThickness = 1;
rootGrid.Children.Add(curLine);
//save pointer id so that no other pointer can ink until this one is released
pointerId = (int)pointerPoint.PointerId;
}
}
}

TA貢獻1785條經(jīng)驗 獲得超4個贊
您有一個點集合,您可以從這些點繪制一條折線并將其添加到網(wǎng)格中。
private void CreatePolyline()
{
// Initialize a new Polyline instance
Polyline polyline = new Polyline();
// Set polyline color
polyline.Stroke = new SolidColorBrush(Colors.Black);
// Set polyline width/thickness
polyline.StrokeThickness = 10;
// Initialize a point collection
var points = new PointCollection();
points.Add(new Point(20, 100));
points.Add(new Point(35, 150));
points.Add(new Point(60, 200));
points.Add(new Point(90, 250));
points.Add(new Point(40, 300));
// Set polyline points
polyline.Points = points;
// Finally, add the polyline to layout
grid.Children.Add(polyline);
}
或者,為了測試觸摸屏的完整性,您可以使用另一個用戶控件InkCanvas,而無需以編程方式繪制線條。
首先,刪除你所做的所有代碼,這樣你就有了一個空白的 Grid 'grid'。
在設計器中,將InkCanvas控件拖動到“網(wǎng)格”。
并從后面的代碼啟用觸摸功能:
inkCanvas.InkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Touch;
就這些。
要清除 中的墨水,您可以在您提到的單獨事件InkCanvas中簡單地調(diào)用它,
inkCanvas.InkPresenter.StrokeContainer.Clear();
- 2 回答
- 0 關(guān)注
- 181 瀏覽
添加回答
舉報