| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows;
- using System.Windows.Media;
- namespace MuchInfo.Chart.WPF.Primitives.Drawing
- {
- public class DrawingHost : UIElement
- {
-
- private VisualCollection _children;
- protected override int VisualChildrenCount
- {
- get { return _children.Count; }
- }
- public DrawingHost()
- {
- _children=new VisualCollection(this);
- }
- // Provide a required override for the GetVisualChild method.
- protected override Visual GetVisualChild(int index)
- {
- if (index < 0 || index >= _children.Count)
- {
- throw new ArgumentOutOfRangeException();
- }
- return _children[index];
- }
-
- public void ClearDrawing()
- {
- _children.Clear();
- if (_children != null )
- foreach (var child in _children)
- {
- this.RemoveVisualChild(child);
- }
- }
- public void DrawingLine(Brush penBrush, double thickness, Point point1, Point point2)
- {
- var visual=new DrawingVisual();
-
- var drawContext= visual.RenderOpen();
- drawContext.DrawLine(new Pen(penBrush,thickness),point1,point2);
- drawContext.Close();
- _children.Add(visual);
-
- }
- }
- }
|