我已将此代码放在一起,从(0,0)到(100,100)绘制Line
。我知道如何Bind
StrokeThickness
LineGeometry`的Line' to some other value, but here the line is drawn using
属性没有该属性。如何将其绑定到另一个值(例如Slider.Value)?
var line = new LineGeometry
{
StartPoint = new Point(0, 0),
EndPoint = new Point(100, 100)
};
var geometryGroup = new GeometryGroup();
geometryGroup.Children.Add(line);
var drawing = new GeometryDrawing {Geometry = geometryGroup};
var drawingGroup = new DrawingGroup();
drawingGroup.Children.Add(drawing);
var myPen = new Pen {Thickness = 1, Brush = Brushes.Yellow};
drawing.Pen = myPen;
var myImage = new Image {Stretch = Stretch.None, Margin = new Thickness(10)};
var myDrawingImage = new DrawingImage {Drawing = drawingGroup};
myImage.Source = myDrawingImage;
canvas.Children.Add(myImage);
答案 0 :(得分:1)
使用您分配给LineGeometry
的{{1}}对象绘制Pen
。因此,只需绑定GeometryDrawing.Pen
属性Thickness
,就像之前绑定到Pen
的{{1}}一样。
不同之处在于Thickness
没有Line
方法,正如Pen
所做的那样(继承自SetBinding
)。绑定任何Line
属性的一般方法是使用FrameworkElement
方法:
DependencyObject