c# - Can I know width of TextBlock when create it? -


i create textbox on canvas this:

        textblock t = new textblock();         t.foreground = new solidcolorbrush(...);         t.fontsize = 10;         t.horizontalalignment = horizontalalignment.left;         t.verticalalignment = verticalalignment.top;         t.text = ...;          canvas.setleft(t, "f(width)");         canvas.settop(t, ...);                          canvas.children.add(t); 

i want know width of textblock, because left coordinate depends on this. can it? actualwidth 0. thanks.

before add it, call measure on it, use desiredsize.

edit: ok because canvas not affect size of element once placed. if added to, say, grid fixed-size row, wouldn't give real height once added since adding grid change it.

as mario vernari points out, if have real complex positioning needs it's pretty easy override arrangeoverride (and measureoverride) , make custom panel. canvas written way, stackpanel, etc. specific-measuring , arranging panels, , can make own, too.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -