开发者

How do you get the client size in a Silverlight Application?

开发者 https://www.devze.com 2023-01-05 17:54 出处:网络
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!

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.Cont开发者_JS百科ent.ActualWidth;

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

    }


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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消