我在InkCanvas想作为stroke添加图片,以便和墨迹一起处理。使用inkcanvas的select模式时。点击图片大部分区域不能选中,只有点击边框和从右上角到左下角一条斜线区域可以选中。谁能帮我了解下是哪里出了问题。
private void picbtn1_Click(object sender, RoutedEventArgs e)
{
StylusPointCollection pts = new StylusPointCollection();
pts.Add(new StylusPoint(100, 100)); // LeftTopPoint
pts.Add(new StylusPoint(200, 100));
pts.Add(new StylusPoint(100, 200));
pts.Add(new StylusPoint(200, 200));
Stroke s = new CustomStroke1(pts);
ink.Strokes.Add(s);
}
#region 自定义画图片1
public class CustomStroke1 : Stroke
{
private StylusPointCollection s;
public CustomStroke1(StylusPointCollection stylusPoints) : base(stylusPoints)
{
this.s = stylusPoints;
}
//public bool IsSelected
//{
// //get
// //{
// // PropertyInfo property = typeof(Stroke).GetProperty("IsSelected",
// // System.Reflection.BindingFlags.Instance |
// // System.Reflection.BindingFlags.GetProperty |
// // System.Reflection.BindingFlags.NonPublic);
// // return (bool)property.GetValue(this, null);
// //}
//}
protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes)
{
ImageSource imageSource = new BitmapImage(new Uri("pack://application:,,,/0.bmp"));
System.Windows.Point topLeft = new System.Windows.Point(StylusPoints[0].X, StylusPoints[0].Y);//100, 100
System.Windows.Point topRight = new System.Windows.Point(StylusPoints[1].X, StylusPoints[1].Y);//200, 100
System.Windows.Point centerLeft = new System.Windows.Point(StylusPoints[2].X, StylusPoints[2].Y);//100, 200
System.Windows.Point centerRight = new System.Windows.Point(StylusPoints[3].X, StylusPoints[3].Y);//200, 200
PathGeometry pathGeomery = new PathGeometry();
PathSegmentCollection pathCollection = new PathSegmentCollection();
pathCollection.Add(new LineSegment(topLeft, true));
pathCollection.Add(new LineSegment(topRight, true));
pathCollection.Add(new LineSegment(centerRight, true));
pathCollection.Add(new LineSegment(centerLeft, true));
pathCollection.Add(new LineSegment(topLeft, true));
PathFigure pathFigure = new PathFigure();
pathFigure.IsClosed = true;
pathFigure.IsFilled = true;
pathFigure.StartPoint = topLeft;
pathFigure.Segments = pathCollection;
//图片刷
ImageBrush myimageBrush = new ImageBrush();
myimageBrush.ImageSource = imageSource;
PathFigureCollection pathFigureCollection = new PathFigureCollection();
pathFigureCollection.Add(pathFigure);
pathGeomery.Figures = pathFigureCollection;
drawingContext.DrawGeometry(myimageBrush, new System.Windows.Media.Pen(System.Windows.Media.Brushes.Blue, 2), pathGeomery);
this.s = null;
}
}
#endregion