I'm trying to use manipulation to rescale a canvas. On debugging the below code it seems that canImage.Width and canImage.Heigh both get set to NaN
. I don't understand how a double times a double can give Nan
(width ~ 400 Height ~400 e.scale.y ~-1.5 e.Scale.X ~0.3)
.
private void viewer_ManipulationCompleted(object sender, System.Windows.Input.ManipulationCompletedEventArgs e)
{
if (e.TotalManipulation.Scale.X != 0 && e.TotalManipulation.Scale.Y != 0) {
开发者_如何学运维 canImage.Width = mainImage.Width * (double)e.TotalManipulation.Scale.X;
canImage.Height = mainImage.Height * (double)e.TotalManipulation.Scale.Y;
}
}
EDIT: Just put a conditional breakpoint in and it seems e.TotalManipulation.Scale.X
and e.TotalManipulation.Scale.X
are never NaN
. Putting the e.TotalManipulation.Scale.X > 0
condition did stop the issue. It looks like setting Height/Width to something less than one just causes them to become NaN rather than just falling over. Thanks for all your help
Is that negative sign supposed to be there for e.scale.y = -1.5? Setting the height to a negative number may explain your problems.
If e.TotalManipulation.Scale.X
or e.TotalManipulation.Scale.Y
are equal to NaN
, then the product will be equal to NaN
. Try testing using the following instead (since you wouldn't want negative numbers either):
if (e.TotalManipulation.Scale.X > 0 && e.TotalManipulation.Scale.Y > 0)
精彩评论