PDA

View Full Version : ScaleTransform - one for kirupa maybe



Charleh
March 12th, 2009, 03:18 PM
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)
49390

And just WHAT IS GOING ON HERE?
49391

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



void Resize()
{
// The _originalWidth and height are just constants got from app startup
double currentWidth = Application.Current.Host.Content.ActualWidth;
double currentHeight = Application.Current.Host.Content.ActualHeight;

// Get min value to maintain aspect ratio
double uniformScaleAmount = Math.Min((currentWidth / _originalWidth), (currentHeight / _originalHeight));

scaleTransform.ScaleX = uniformScaleAmount;
scaleTransform.ScaleY = uniformScaleAmount;
}

kirupa
March 13th, 2009, 05:15 AM
Charley - can you attach your full code?

Thanks,
Kirupa

Charleh
March 13th, 2009, 07:00 AM
Here you go! Am I doing something horribly wrong?

49397

Charleh
March 16th, 2009, 11:11 AM
Still not figured this one out - also does anyone know how to make the unused area of the Silverlight control a specific colour? It seems like my unused control area is white but no matter what I do with page.xaml or my user controls it stays white in the unused space!

Here's an example - I want all the white to be the sandy colour

49415

All the white is definitely the Silverlight control - I can right click for the menu

kirupa
March 16th, 2009, 03:26 PM
Sorry - I've been swamped with some other things, but I will look into it shortly.

One thing you can look at in the interim is the ViewBox Layout panel: http://silverlight.codeplex.com/Wiki/View.aspx?title=Silverlight%20Toolkit%20Overview%2 0Part%201&referringTitle=Home It is a part of the Silverlight Toolkit.

Essentially, any content you place inside this layout panel scales all of its contents depending on how much space is available. This is basically what you are trying to do, except the control takes care of the details automatically for you.

You can fiddle with the version of ViewBox that is already available in WPF to get a feel for it if you don't feel like downloading the toolkit and referencing the assembly yet.

:)

Charleh
March 18th, 2009, 11:45 AM
Cheers, will try using it! Now we just need to get this working over https with web service calls and data compression!