none
如何把System.Windows.Ink.Stroke转换为自定义Stroke? RRS feed

  • 问题

  • 如何把System.Windows.Ink.Stroke转换为自定义Stroke吗?自定义墨迹继承了Stroke

    DesignerStroke s ;
               StrokeCollection strokes = new StrokeCollection(fileStream);
                foreach (var item in strokes)
                {
                    s = (DesignerStroke)item;      这几句会报错。无法将类型为“System.Windows.Ink.Stroke”的对象强制转换为类型“HF.WhiteBoardCommon.CanvasDesigner.DesignerStroke”。
                    inkcanvas.Strokes.Add(s);
                }

    2018年7月5日 7:00

全部回复

  • 你好,

    你可以在转换之前做一个判断,如果是DesignerStroke的话,在转换。下面的代码你可以参考一下。

    DesignerStroke s ;
    StrokeCollection strokes = new StrokeCollection(fileStream);
    foreach (var item in strokes)
     {
         if (item is DesignerStroke)
         {
              s = (DesignerStroke)item;      
              inkcanvas.Strokes.Add(s);
         }
    }

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2018年7月6日 5:13