wp7 开发学习之 Inkpresenter 小应用

xaml页面

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<InkPresenter Height="629"
HorizontalAlignment="Left"
Margin="-12,-22,0,0"
Name="inkPresenter1"
VerticalAlignment="Top"
Width="462"
LostMouseCapture="inkPresenter1_LostMouseCapture"
MouseLeftButtonDown="inkPresenter1_MouseLeftButtonDown"
MouseMove="inkPresenter1_MouseMove"
Background="white"/>
</Grid>

 

cs页面

public partial class InkPresenter : PhoneApplicationPage
{
Stroke NewStroke;
public InkPresenter()
{
InitializeComponent();
}

private void inkPresenter1_LostMouseCapture(object sender, MouseEventArgs e)
{
//将笔画清空
NewStroke = null;
}

private void inkPresenter1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
//让鼠标捕获数据
inkPresenter1.CaptureMouse();
//收集笔触数据点保存值StylusPointCollection集合中
StylusPointCollection spc = new StylusPointCollection();
spc.Add(e.StylusDevice.GetStylusPoints(inkPresenter1));
//将数据点的结合保存为一个笔画
NewStroke = new Stroke(spc);
//设置笔画的绘画效果,如颜色,大小等。
NewStroke.DrawingAttributes.Color = Colors.Red;
this.inkPresenter1.Strokes.Add(NewStroke);

}

private void inkPresenter1_MouseMove(object sender, MouseEventArgs e)
{
//在鼠标移动的过程中将数据点加入到笔画中去。
if (NewStroke!=null)
{
NewStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(inkPresenter1));
}
}
}

 

都有注释自己看下哦!

你可能感兴趣的:(wp7,inkpresenter)