tags:

views:

367

answers:

2

I want to get the size of the browser window running my Silverlight Application? I've tried the following lines, but it always returns zero!

public Page()
    {
        InitializeComponent();
        Initialize();

    }

    public void Initialize()
    {

        WorldLimits.Y = Application.Current.Host.Content.ActualHeight;
        WorldLimits.X = Application.Current.Host.Content.ActualWidth;

        gameCore = new GameCore(this);
        gameTime = DateTime.Now.TimeOfDay.TotalMilliseconds / 1000;

    }
+2  A: 

Make sure that you're grabbing the values in an event handler

public Page()
{
    InitializeComponent();
    App.Current.Host.Content.Resized += new EventHandler(Content_Resized);
}

void Content_Resized(object sender, EventArgs e)
{    
    this.Width = App.Current.Host.Content.ActualWidth;
    this.Height = App.Current.Host.Content.ActualHeight;
}
jcollum
This is the complete block public Page() { InitializeComponent(); Initialize(); } public void Initialize() { WorldLimits.Y = Application.Current.Host.Content.ActualHeight; WorldLimits.X = Application.Current.Host.Content.ActualWidth; gameCore = new GameCore(this); gameTime = DateTime.Now.TimeOfDay.TotalMilliseconds / 1000; }
Stefan
It'd be better if you edited your original answer to reflect the new code. That's usually what we do around here. If you're used to forums SO can seem odd at first, but in practice it works much better.
jcollum
If you can't read that, it does happen after the Initialize component
Stefan
(code and comments don't get along around here)
jcollum
Done. Thanks for the tip!
Stefan
Well, done editing my post, the problem still exists.
Stefan
deleting answer, should've been in comments
jcollum
A: 

very nice one !! thanks for the :)

dan