ScaleTransform - one for kirupa maybe

Hi all,

I’ve got my Silverlight app working, all works great and it’s coming along nicely - the only problem I’m having is scaling the app within the browser.

I want the app to be default of 800x600 wide within a 1024x768 screen which will be the minimum, but on the off chance that the user has an 800x600 res screen I want the app to scale down a little to fit within the smaller window.

I’ve written scaling code which scales the app perfectly using a scaletransform. However, on scales smaller than the original size (e.g. I set the original size to 400x300 and when it gets smaller than that i.e. scales less than 1.0) some of the app is being clipped. The app should stretch to the edge of the browser window - but it’s being clipped off early! The clip increases as the scale size gets smaller - it looks like a bug to me with scaling.

I’ve tried this in a new empty Silverlight app and I have the same problem.

Here are some screenies

Good scaling (the app scale is greater than or equal to 1)

And just WHAT IS GOING ON HERE?

Now this isn’t much of a problem with a 400x300 app - no screen is going to be smaller than that, but my app is designed for a minimum of 800x600 - so I can’t go and move all the controls about the place! That’s what scaling is for!!!

Here’s the code I’m using


[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Resize()
{
    // The _originalWidth and height are just constants got from app startup
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]    double[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] currentWidth = [/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Application[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Current.Host.Content.ActualWidth;
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]    double[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] currentHeight = [/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Application[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Current.Host.Content.ActualHeight;[/SIZE]
[SIZE=2][/SIZE] 
[SIZE=2]    // Get min value to maintain aspect ratio
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]    double[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] uniformScaleAmount = [/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Math[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Min((currentWidth / _originalWidth), (currentHeight / _originalHeight));[/SIZE]
[SIZE=2] 
    scaleTransform.ScaleX = uniformScaleAmount;
    scaleTransform.ScaleY = uniformScaleAmount;
}

[/SIZE]