Referencing code found at...Highlight a Route on a Map
They show...
var customMap = new CustomMap
{
WidthRequest = App.ScreenWidth
};
App.ScreenWidth isn't available any longer. Has it been replaced with Application.Current.MainPage.Width?
In that demo, App.ScreenWidth and App.ScreenHeight are static variables defined in the App class and assigned in the native projects:
iOS app project:
App.ScreenWidth = UIScreen.MainScreen.Bounds.Width;
App.ScreenHeight = UIScreen.MainScreen.Bounds.Height
Android app project:
App.ScreenWidth = (width - 0.5f) / density;
App.ScreenHeight = (height - 0.5f) / density;
Ref: https://github.com/xamarin/recipes/search?p=2&q=ScreenWidth&utf8=✓
Most simplest and accurate way to get device height & width in PCL:
using Xamarin.Forms;
namespace ABC
{
public class MyPage : ContentPage
{
private double _width;
private double _height;
public MyPage()
{
Content = new Label
{
WidthRequest = _width,
Text = "Welcome to Xamarin.Forms!"
};
}
protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);
_width = width;
_height = height;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With