From e1b66cb4fcc680dd2b8d1a23fcf51374e100fa7c Mon Sep 17 00:00:00 2001 From: Agustin Bonilla Date: Sun, 26 Nov 2023 16:12:06 -0300 Subject: [PATCH] Fix issue and add improvements to MaterialDialog --- MaterialDialog.md | 12 +++++ .../Pages/MaterialDialogPage.xaml | 16 ++++--- .../ControlsMaterial3/MaterialCheckBox.cs | 8 +++- .../ControlsMaterial3/MaterialDialog.cs | 44 +++++++++++++++++-- 4 files changed, 70 insertions(+), 10 deletions(-) diff --git a/MaterialDialog.md b/MaterialDialog.md index 45261ed7..31b0687d 100644 --- a/MaterialDialog.md +++ b/MaterialDialog.md @@ -133,6 +133,10 @@ This property is to the font size of the cancel button. This property is to the font family of the cancel button.
+### Property CancelCornerRadius: +This property is to set the corner radius of cancel button. +
+ ### Property CancelCommand: This property is to the command of the cancel button.
@@ -165,6 +169,10 @@ This property is to the font size of the accept button. This property is to the font family of the accept button.
+### Property AcceptCornerRadius: +This property is to set the corner radius of accept button. +
+ ### Property AcceptCommand: This property is to the command of the accept button.
@@ -264,4 +272,8 @@ This property is to set the icon when is unchecked. It is a DataTemplate propert ### Property ItemCheckboxSize This property is to set the size of the checkbox. +
+ +### Property ItemCheckboxSpacing +This property is to set the spacing of the checkbox.
\ No newline at end of file diff --git a/example/ExampleMaterialDesignControls/Pages/MaterialDialogPage.xaml b/example/ExampleMaterialDesignControls/Pages/MaterialDialogPage.xaml index 524d98c4..11b861cd 100644 --- a/example/ExampleMaterialDesignControls/Pages/MaterialDialogPage.xaml +++ b/example/ExampleMaterialDesignControls/Pages/MaterialDialogPage.xaml @@ -59,16 +59,17 @@ + HeightRequest="500" + AllowMultiselect="True" /> @@ -100,15 +101,18 @@ DividerColor="DarkBlue" CancelTextColor="DarkBlue" CancelFontSize="12" - AcceptTextColor="DarkBlue" - AcceptBackgroundColor="Transparent" + CancelCornerRadius="4" + AcceptTextColor="LightSkyBlue" + AcceptBackgroundColor="DarkBlue" AcceptFontSize="16" + AcceptCornerRadius="4" SearchTextColor="DarkBlue" SearchBackgroundColor="LightSkyBlue" SearchTextAlignment="Center" ItemTextFontSize="14" ItemTextColor="DarkBlue" - HeightRequest="500"> + HeightRequest="500" + ItemCheckboxSpacing="0"> diff --git a/src/MaterialDesignControls/ControlsMaterial3/MaterialCheckBox.cs b/src/MaterialDesignControls/ControlsMaterial3/MaterialCheckBox.cs index 7cc4663e..020008ef 100644 --- a/src/MaterialDesignControls/ControlsMaterial3/MaterialCheckBox.cs +++ b/src/MaterialDesignControls/ControlsMaterial3/MaterialCheckBox.cs @@ -171,7 +171,9 @@ private void Initialize() VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center, WidthRequest = 40, - HeightRequest = 40 + HeightRequest = 40, + MinimumWidthRequest = 40, + MinimumHeightRequest = 40 }; _chk = new CustomCheckBox() @@ -204,6 +206,8 @@ private void Initialize() HorizontalOptions = LayoutOptions.Center, WidthRequest = 40, HeightRequest = 40, + MinimumWidthRequest = 40, + MinimumHeightRequest = 40, IsVisible = false }; @@ -232,6 +236,8 @@ private void Initialize() HorizontalOptions = LayoutOptions.Center, WidthRequest = 40, HeightRequest = 40, + MinimumWidthRequest = 40, + MinimumHeightRequest = 40, IsVisible = false }; diff --git a/src/MaterialDesignControls/ControlsMaterial3/MaterialDialog.cs b/src/MaterialDesignControls/ControlsMaterial3/MaterialDialog.cs index 1d4a934e..1de5ca78 100644 --- a/src/MaterialDesignControls/ControlsMaterial3/MaterialDialog.cs +++ b/src/MaterialDesignControls/ControlsMaterial3/MaterialDialog.cs @@ -313,6 +313,15 @@ public bool CancelIsBusy set { SetValue(CancelIsBusyProperty, value); } } + public static readonly BindableProperty CancelCornerRadiusProperty = + BindableProperty.Create(nameof(CancelCornerRadius), typeof(float), typeof(MaterialDialog), defaultValue: 20f); + + public float CancelCornerRadius + { + get { return (float)GetValue(CancelCornerRadiusProperty); } + set { SetValue(CancelCornerRadiusProperty, value); } + } + #endregion CancelButton #region AcceptButton @@ -389,6 +398,15 @@ public bool AcceptIsBusy set { SetValue(AcceptIsBusyProperty, value); } } + public static readonly BindableProperty AcceptCornerRadiusProperty = + BindableProperty.Create(nameof(AcceptCornerRadius), typeof(float), typeof(MaterialDialog), defaultValue: 20f); + + public float AcceptCornerRadius + { + get { return (float)GetValue(AcceptCornerRadiusProperty); } + set { SetValue(AcceptCornerRadiusProperty, value); } + } + #endregion AcceptButton public static readonly BindableProperty ButtonsAlignmentProperty = @@ -568,6 +586,15 @@ public double ItemCheckboxSize set { SetValue(ItemCheckboxSizeProperty, value); } } + public static readonly BindableProperty ItemCheckboxSpacingProperty = + BindableProperty.Create(nameof(ItemCheckboxSpacing), typeof(double), typeof(MaterialDialog), defaultValue: 10.0); + + public double ItemCheckboxSpacing + { + get { return (double)GetValue(ItemCheckboxSpacingProperty); } + set { SetValue(ItemCheckboxSpacingProperty, value); } + } + #endregion Items #region Constructor @@ -691,6 +718,10 @@ protected override void OnPropertyChanged([CallerMemberName] string propertyName _cancelBtn.IsBusy = CancelIsBusy; break; + case nameof(CancelCornerRadius): + _cancelBtn.CornerRadius = CancelCornerRadius; + break; + case nameof(AcceptText): _acceptBtn.Text = AcceptText; break; @@ -719,6 +750,10 @@ protected override void OnPropertyChanged([CallerMemberName] string propertyName _acceptBtn.IsBusy = AcceptIsBusy; break; + case nameof(AcceptCornerRadius): + _acceptBtn.CornerRadius = AcceptCornerRadius; + break; + case nameof(CancelCommand): _cancelBtn.Command = CancelCommand; break; @@ -890,7 +925,8 @@ private void Initialize() BackgroundColor = CancelBackgroundColor, Command = CancelCommand, IsVisible = !string.IsNullOrWhiteSpace(CancelText), - MinimumWidthRequest = 80 + MinimumWidthRequest = 80, + CornerRadius = CancelCornerRadius }; _acceptBtn = new MaterialButton @@ -903,7 +939,8 @@ private void Initialize() BackgroundColor = AcceptBackgroundColor, Margin = new Thickness(0), Command = AcceptCommand, - MinimumWidthRequest = 80 + MinimumWidthRequest = 80, + CornerRadius = AcceptCornerRadius }; _btnsContainer.Children.Add(_cancelBtn); @@ -913,7 +950,6 @@ private void Initialize() Content = _mainContainer; - //Xamarin.Forms.PlatformConfiguration.AndroidSpecific.VisualElement.SetElevation(this, 0); initialized = true; } } @@ -952,6 +988,8 @@ private void RefreshItemList(IEnumerable list) materialCheckbox.CustomSelectedIcon = ItemCheckboxCustomSelectedIcon; materialCheckbox.CustomUnselectedIcon = ItemCheckboxCustomUnselectedIcon; materialCheckbox.IsChecked = item.IsSelected; + materialCheckbox.Spacing = ItemCheckboxSpacing; + materialCheckbox.IsRadioButtonStyle = !AllowMultiselect; _optionsContainer.Children.Add(materialCheckbox); }