如何在Silverlight应用程序中获取客户端大小?

时间:2009-07-15 17:42:54

标签: silverlight

我想获得运行Silverlight应用程序的浏览器窗口的大小?我尝试了以下几行,但它总是返回零!

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;

    }

1 个答案:

答案 0 :(得分:6)

确保您正在抓取事件处理程序中的值

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