Xamarin Forms覆盖视图模型中的OnSizeAllocated方法

时间:2017-07-25 09:47:33

标签: c# mvvm xamarin.forms prism

我在我的xamarin表单项目中使用了Prism。目前我已经在视图类中重写了OnSizeAllocated方法。如何在视图模型中实现OnSizeAllocated方法?换句话说,是否可以在视图模型中覆盖OnSizeAllocated方法?

这是我要实现的一段代码: -

        private double width = 0;
        private double height = 0;
        protected override void OnSizeAllocated(double width, double height)
        {
            try
            {
               if (App.vw_CurrentPage == "Bandwidth")
             {
                base.OnSizeAllocated(width, height); //must be called
                if (this.width != width || this.height != height)
                {
                    this.width = width;
                    this.height = height;
                    double dEntryWidth = (width / 11) * 7;
                    double dEntryWidth1 = (width / 9) * 6;
                    double dGridHeight = height * 0.352;
                    txtBandwidthHotel.WidthRequest = dEntryWidth1;
                }
              }
            }
            catch (Exception ex)
            {

            }
        }

0 个答案:

没有答案