How to get client size in Silverlight application?

I want to get the browser window size with my Silverlight application? I 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;

    }
+3
source share
1 answer

Make sure you capture the values ​​in the 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;
}
+6
source

Source: https://habr.com/ru/post/1712698/


All Articles