c# - How do draw FormattedText (if not in the onRender method) -
i draw ellipse , add them grid.
then i'd add formattedtext each ellipse. getting rectanglebounds of ellipse.
but following example:
http://msdn.microsoft.com/en-us/library/bb613560.aspx#formattedtext_object
i need drawingcontext draw text. if don't wantto override onrender, how can drawingcontext?
you can use drawinggroup instead. has open method returns drawingcontext , can use construct drawing.
you'll need arrange drawing appear in ui somehow. easiest way wrap in drawingbrush , use paint existing element in ui. example, if you've got ellipse called myellipse, set fill property drawingbrush based on drawinggroup contains single bit of formattedtext:
var drawing = new drawinggroup(); using (var context = drawing.open()) { var text = new formattedtext("this text", cultureinfo.currentculture, flowdirection.lefttoright, new typeface("calibri"), 30, brushes.green); context.drawtext(text, new point(0, 0)); } var db = new drawingbrush(drawing); db.stretch = stretch.none; myellipse.fill = db; if you've filled ellipse else, have 2 choices. either add more content drawing - can make many calls context like. example, if add before call context.drawtext:
context.drawrectangle(brushes.cyan, null, new rect(0, 0, 300, 100)); i'll cyan background behind text. (you'd need adjust coordinates in these examples suit layout, of course.)
but it's simpler add element host drawing, rather trying piggy-back element that's there else. put rectangle element positioned directly on ellipse, , use drawingbrush such fill rectangle. rectangle won't rectangular, because drawingbrush doesn't paint in whole area. effect same if you'd layered textblock on ellipse.
Comments
Post a Comment