c# - Resize WPF Canvas control not maintaining aspect ratio correctly -
i using resize code this answer works when testing when placed real application (with larger render time) aspect ratio no no longer maintained. if move mouse or wiggle in directions can make control distort out of original aspect ratio , seems happen once in actual application.
i'm not 100% sure wonder if because uses actualheight
, actualwidth
calculate current ratio , values might not date.
some of related code, rest available on question linked above:
called on drag
this.checkaspectratio(ref dragdeltahorizontal, ref dragdeltavertical, item.actualheight / item.actualwidth);
the function itself
private void checkaspectratio(ref double? dragdeltahorizontal, ref double? dragdeltavertical, double aspectratio) { double? dragvalue = null; if (dragdeltavertical.hasvalue && dragdeltahorizontal.hasvalue) { dragvalue = math.max(dragdeltavertical.value, dragdeltahorizontal.value); } else if (dragdeltavertical.hasvalue) { dragvalue = dragdeltavertical; } else if (dragdeltahorizontal.hasvalue) { dragvalue = dragdeltahorizontal; } if (dragvalue.hasvalue) { dragdeltavertical = dragvalue.value * aspectratio; dragdeltahorizontal = dragvalue; } }
Comments
Post a Comment