使用CustomRenderer获取Xamarin Forms中ContentPage的高度

问题描述

我想使用CustomRenderer尝试导航栏的高度,但无论是Android平板电脑还是平板电脑,总是得到相同的值。

我正在使用以下代码

namespace OfflineFieldService.Droid
{
    public class CustomAndroidPageRenderer : PageRenderer
    {
        public CustomAndroidPageRenderer(Context context) : base(context)
        {

        }

        protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
        {
            base.OnElementChanged(e);
            var height = 0;
            var resources = Context.Resources;
            int resourceId = resources.GetIdentifier("navigation_bar_height","dimen","android");
            if (resourceId > 0)
            {
                height = resources.GetDimensionPixelSize(resourceId);
            }
            var scale = Resources.DisplayMetrics.Density;
            var heightinUnits = (height - .5) / scale;
            App.screenHeight = heightinUnits;

        }
    }```

[Attached image in the link,since dont have permission to embed][1]


  [1]: https://i.stack.imgur.com/UosCb.png

In the image whatever marked in yellow,need to get the height of it. I am using Shell template.

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)