private void ResponsiveMasterDetail_SizeChanged(object sender, EventArgs e) { Enums.DeviceSize deviceSize = Common.GetCurrentDeviceSize(); _masterGrid = new Grid() { ColumnSpacing = 0, RowSpacing = 0 }; _detailGrid = new Grid() { ColumnSpacing = 0, RowSpacing = 0 }; _buttonBack = new Button(); if (MasterHeader == null) { _masterHeader = new Grid(); _masterHeader.Padding = new Thickness(8); _masterHeader.Children.Add(new Label { Text = Title, HorizontalOptions = LayoutOptions.Center, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), VerticalOptions = LayoutOptions.Center }); _masterHeader.BackgroundColor = Color.Silver; } else { _masterHeader = MasterHeader as Layout <View>; if (_masterHeader.BackgroundColor.Equals(Color.Default)) { _masterHeader.BackgroundColor = Color.Silver; } } if (deviceSize.Equals(Enums.DeviceSize.Medium) || deviceSize.Equals(Enums.DeviceSize.Large) || deviceSize.Equals(Enums.DeviceSize.ExtraLarge)) { LayoutMedium(); } else if (deviceSize.Equals(Enums.DeviceSize.Small)) { LayoutSmall(); } else if (deviceSize.Equals(Enums.DeviceSize.ExtraSmall)) { LayoutExtraSmall(); } LayoutCommon(); }
private static void OnIsDetailVisibleChanged(BindableObject bindable, object oldValue, object newValue) { var item = (ResponsiveMasterDetail)bindable; if (newValue == oldValue) { return; } bool newVal = Convert.ToBoolean(newValue); Enums.DeviceSize deviceSize = Common.GetCurrentDeviceSize(); if (deviceSize.Equals(Enums.DeviceSize.Small)) { if (!newVal) { item._buttonBack.SetValue(AbsoluteLayout.LayoutBoundsProperty, new Rectangle(item._masterGrid.Width, 0, item._buttonBack.Width, item._buttonBack.Height)); item._masterGrid.SetValue(AbsoluteLayout.LayoutBoundsProperty, new Rectangle(0, 0, item._masterGrid.Width, 1)); } else { item._buttonBack.SetValue(AbsoluteLayout.LayoutBoundsProperty, new Rectangle(0, 0, item._buttonBack.Width, item._buttonBack.Height)); item._masterGrid.SetValue(AbsoluteLayout.LayoutBoundsProperty, new Rectangle(-item._masterGrid.Width, 0, item._masterGrid.Width, 1)); } } else if (deviceSize.Equals(Enums.DeviceSize.ExtraSmall)) { if (newVal) { item._masterGrid.SetValue(AbsoluteLayout.LayoutBoundsProperty, new Rectangle(-item._masterGrid.Width, 0, 1, 1)); } else { item._masterGrid.SetValue(AbsoluteLayout.LayoutBoundsProperty, new Rectangle(0, 0, 1, 1)); } } }
private void ResponsiveMasterDetail_SizeChanged(object sender, EventArgs e) { Enums.DeviceSize deviceSize = Common.GetCurrentDeviceSize(); if (_lastDeviceSize != deviceSize) { if (IsMasterVisible) { IsMasterVisible = false; } _lastDeviceSize = deviceSize; this.SizeChanged -= ResponsiveMasterDetail_SizeChanged; try { if (MasterHeader == null) { // _masterGridHeader = new Grid() { ColumnSpacing = 0, RowSpacing = 0, BackgroundColor = Color.White, Padding = new Thickness(8), Margin = new Thickness(1) }; _masterGridHeader = new Label { Text = Title, TextColor = Color.Black, HorizontalOptions = LayoutOptions.Center, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), VerticalOptions = LayoutOptions.Center }; } else { _masterGridHeader = MasterHeader as VisualElement; if (_masterGridHeader.BackgroundColor.Equals(Color.Default)) { _masterGridHeader.BackgroundColor = Color.White; } //if (_masterGridHeader.Margin == new Thickness(0)) // _masterGridHeader.Margin = new Thickness(1); } //_masterGrid.Children.Remove(_masterGridHeader as View); //if (MasterContent != null) // _masterGrid.Children.Remove(MasterContent as View); //if (DetailHeader != null) // _detailGrid.Children.Remove(DetailHeader as View); //if (DetailContent != null) //{ // if (DetailContent is Page) // _detailGrid.Children.Remove(_container); // else // _detailGrid.Children.Remove(DetailContent as View); //} if (ShowDetailHeader) { try { if (_detailGrid.RowDefinitions.Count != 3) { _detailGrid.RowDefinitions.Clear(); _detailGrid.RowDefinitions.Add(new RowDefinition { Height = 42 }); _detailGrid.RowDefinitions.Add(new RowDefinition { Height = 1 }); _detailGrid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Star }); } Grid.SetRow(_horizontalLineDetail, 1); _horizontalLineDetail.IsVisible = true; if (!_detailGrid.Children.Any(o => o.Equals(_horizontalLineDetail))) { _detailGrid.Children.Add(_horizontalLineDetail); } } catch (Exception ex) { throw; } } if (deviceSize.Equals(Enums.DeviceSize.Medium) || deviceSize.Equals(Enums.DeviceSize.Large) || deviceSize.Equals(Enums.DeviceSize.ExtraLarge)) { LayoutMedium(); } else if (deviceSize.Equals(Enums.DeviceSize.Small)) { LayoutSmall(); } else if (deviceSize.Equals(Enums.DeviceSize.ExtraSmall)) { LayoutExtraSmall(); } LayoutCommon(); } finally { this.SizeChanged += ResponsiveMasterDetail_SizeChanged; } } }
private static void OnIsMasterVisibleChanged(BindableObject bindable, object oldValue, object newValue) { var item = (ResponsiveMasterDetail)bindable; if (newValue == oldValue) { return; } bool newVal = Convert.ToBoolean(newValue); Enums.DeviceSize deviceSize = Common.GetCurrentDeviceSize(); if (item.CollapsableInMedium && (deviceSize.Equals(Enums.DeviceSize.Medium) || deviceSize.Equals(Enums.DeviceSize.Large) || deviceSize.Equals(Enums.DeviceSize.ExtraLarge))) { if (newVal) { item._masterGrid.WidthRequest = item.MasterWidth; } else { item._masterGrid.WidthRequest = item.CollapsedMediumMasterWidth; } item.ArrangeMediumContent(); } else if (deviceSize.Equals(Enums.DeviceSize.Small)) { if (newVal) { if (item._buttonBack != null) { item._buttonBack.SetValue(AbsoluteLayout.LayoutBoundsProperty, new Rectangle(item._masterGrid.Width, 0, item._buttonBack.Width, item._buttonBack.Height)); } item._masterGrid.SetValue(AbsoluteLayout.LayoutBoundsProperty, new Rectangle(0, 0, item._masterGrid.Width, 1)); item._overLay.IsVisible = true; } else { if (item._buttonBack != null) { item._buttonBack.SetValue(AbsoluteLayout.LayoutBoundsProperty, new Rectangle(0, 0, item._buttonBack.Width, item._buttonBack.Height)); } item._masterGrid.SetValue(AbsoluteLayout.LayoutBoundsProperty, new Rectangle(-item._masterGrid.Width, 0, item._masterGrid.Width, 1)); item._overLay.IsVisible = false; } } else if (deviceSize.Equals(Enums.DeviceSize.ExtraSmall)) { if (!newVal) { if (item._buttonBack != null) { item._buttonBack.IsVisible = true; } item._masterGrid.SetValue(AbsoluteLayout.LayoutBoundsProperty, new Rectangle(-item._masterGrid.Width, 0, 1, 1)); } else { if (item._buttonBack != null) { item._buttonBack.IsVisible = false; } item._masterGrid.SetValue(AbsoluteLayout.LayoutBoundsProperty, new Rectangle(0, 0, 1, 1)); } } }