c# - How do you calculate pixel size of string? -


i have string. know font family , font size going displayed in. need know how many pixels text take in ui. can determine whether show element. how that?

i found couple of things, none of them available in windows universal project. example:

edit:

this not web project.

i want calculate size take in ui before in ui.

i think need create textblock in code , assign desired text it. can actual height , width it. see below code

         textblock txt=new textblock();         //set additional properties of textblock here . such font size,font family, width etc.         txt.text = "your text here";         var height = txt.actualheight;         var width = txt.actualwidth; 

you can further operations based on height , width

i not saying optimized solution .but work you


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -