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
Post a Comment