c# - Best way for acquiring an element's height -


the code gets desired height element given datatemplate , object bound content. however, slow. have alternative, or idea how optimize code.

public static double getdesiredheight(object content, datatemplate  datatemplate) {         try         {             contentpresenter element = new contentpresenter             {                 content = content,                 contenttemplate = datatemplate,             };              element.measure(new size(double.positiveinfinity, double.positiveinfinity));             var result = element.desiredsize.height;             element.contenttemplate = null;             return result;         }         catch (exception)         {             return 0;         } } 

have tried using actualheight property instead of height property?

try change line:

var result = element.desiredsize.actualheight; 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -