积极答复者
请问使用DynamicRenderer以后,为什么不动态显示绘制的轨迹?

问题
-
我使用DynamicRenderer绘制轨迹,为什么只显示静态笔画,而动态笔画显示不出来呢?
例子地址:https://skydrive.live.com/redir.aspx?cid=8f125a6da8d15aee&resid=8F125A6DA8D15AEE!103
基本代码如下:
主窗口:
private void canvas1_MouseDown(object sender, MouseButtonEventArgs e)
{
Point pt = e.GetPosition(this.canvas1);
if (DrawType == 1)
{
CurItem = new NormalPen(this.canvas1);
this.canvas1.Children.Add(CurItem);
Canvas.SetLeft(CurItem, 0);
Canvas.SetTop(CurItem, 0);
this.CurItem.RenderSize = new Size(SystemParameters.PrimaryScreenWidth, SystemParameters.PrimaryScreenHeight);
this.CurItem.Background = new SolidColorBrush(Colors.Transparent);
this.CurItem.CustomDown(pt);
}
}
自定义的类:
InkPresenter ip;
DynamicRenderer dr;
StylusPointCollection stylusPoints = null;
/// <summary>
///
/// </summary>
public NormalPen(Canvas owner)
{
ip = new InkPresenter();
this.Content = ip;
dr = new DynamicRenderer();
ip.AttachVisuals(dr.RootVisual, dr.DrawingAttributes);
this.StylusPlugIns.Add(dr);
}
private bool isdown = false;
public void CustomDown(Point pt)
{
isdown = true;
if (stylusPoints != null) { return; }
stylusPoints = new StylusPointCollection();
stylusPoints.Add(new StylusPoint(pt.X, pt.Y));
}
答案
-
只是 InkCanvas 不是通过InkPresenter来更新笔迹的,他会调用 MS.Internal.Ink.InkCollectionBehavior.StylusInputBegin 〉 base.InkCanvas.InternalDynamicRenderer.Reset 来 在装饰层进行 OnDraw方法。InkPresenter 在这里作为一个容器使用,本身不起关键作用。还有我观察InkCanvas 有个 EditingCoordinator ,他的UserIsEditing状态在改变 StylusPoints中起了关键作用:
[SecurityCritical] void IStylusEditing.AddStylusPoints(StylusPointCollection stylusPoints, bool userInitiated) { if (!this._disableInput) { if (!base.EditingCoordinator.UserIsEditing) { base.EditingCoordinator.UserIsEditing = true; this.StylusInputBegin(stylusPoints, userInitiated); } else { this.StylusInputContinue(stylusPoints, userInitiated); } } }
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
全部回复
-
你没有实时更新 ip 的Strokes集合。用下面的代码:
public class NormalPen : ContentControl { ...... public void CustomDown(Point pt) { isdown = true; dr.Enabled = true; if (stylusPoints != null) { return; } stylusPoints = new StylusPointCollection(); stylusPoints.Add(new StylusPoint(pt.X, pt.Y)); UpdateStrokes(); } public void CustomMove(Point pt) { if (isdown) { stylusPoints.Add(new StylusPoint(pt.X, pt.Y)); UpdateStrokes(); } } public void CustomUp(Point pt) { if (isdown && stylusPoints != null) { stylusPoints.Add(new StylusPoint(pt.X, pt.Y)); UpdateStrokes(); } isdown = false; } private void UpdateStrokes() { ip.Strokes.Clear(); Stroke stroke = new Stroke(stylusPoints); ip.Strokes.Add(stroke); } }
Sincerely,
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
只是 InkCanvas 不是通过InkPresenter来更新笔迹的,他会调用 MS.Internal.Ink.InkCollectionBehavior.StylusInputBegin 〉 base.InkCanvas.InternalDynamicRenderer.Reset 来 在装饰层进行 OnDraw方法。InkPresenter 在这里作为一个容器使用,本身不起关键作用。还有我观察InkCanvas 有个 EditingCoordinator ,他的UserIsEditing状态在改变 StylusPoints中起了关键作用:
[SecurityCritical] void IStylusEditing.AddStylusPoints(StylusPointCollection stylusPoints, bool userInitiated) { if (!this._disableInput) { if (!base.EditingCoordinator.UserIsEditing) { base.EditingCoordinator.UserIsEditing = true; this.StylusInputBegin(stylusPoints, userInitiated); } else { this.StylusInputContinue(stylusPoints, userInitiated); } } }
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
现在可以把DynamicRenderer的rootisual放入visualcollection中,进行动态展示。但是如果多笔的话,每一笔的动态展示怎么和DynamicRenderer的rootisual进行关联呢?假设我的触摸板支持2个点,我预先加入2个DynamicRenderer。
代码如下:
在OnStylusDown里面应该如何进行处理呢?public class CustomCanvas : Canvas { internal VisualCollection Collection; public CustomCanvas() { Collection = new VisualCollection(this); DynamicRenderer dr = new DynamicRenderer(); Collection.Add(dr.RootVisual); this.StylusPlugIns.Add(dr); DynamicRenderer dr1 = new DynamicRenderer(); Collection.Add(dr1.RootVisual); this.StylusPlugIns.Add(dr1); } protected override Visual GetVisualChild(int index) { return Collection[index]; } protected override int VisualChildrenCount { get { int count = Collection.Count; return count; } } protected override void OnStylusDown(StylusDownEventArgs e) { ?? } }
-
看到了,不过不好意思,我也不是很熟悉。对于它的内部原理,我不确定所以不好说。
还有,InkCanvas的多笔一般是由 触控 来操作。你要分开处理两个点的触控消息,分别让两个 DynamicRenderer 去绘制。
我倒有个建议,你在WPF英文论坛发个贴子吧,那里我可以帮你把贴子提交到更高一层的技术支持哪,看看能不能得到WPF产品组相关的答复。中文这边我不好提交。
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
-
我已上报了你的这个英文贴.应该会有些新的回复的.
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.