我想获得运行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;
}
答案 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;
}