Skip to content

Commit e2b10eb

Browse files
authored
Merge pull request #378 from enisn/fix-selectionview-coloring
Handle dynamic color changes for SelectableButton
2 parents 48567d4 + 0d56bde commit e2b10eb

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/InputKit.Maui/Shared/Controls/SelectionView.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -385,22 +385,30 @@ private void SetInstanceColor(IView view, Color color)
385385
case SelectionType.Button:
386386
case SelectionType.MultipleButton:
387387
{
388-
if (view is Button)
388+
if (view is SelectableButton sb)
389389
{
390-
(view as Button).BackgroundColor = color;
390+
sb.SelectedColor = color;
391+
}
392+
else if (view is Button button)
393+
{
394+
button.BackgroundColor = color;
391395
}
392396
}
393397
break;
394398
case SelectionType.RadioButton:
395399
{
396-
if (view is SelectableRadioButton)
397-
(view as SelectableRadioButton).Color = color;
400+
if (view is SelectableRadioButton srb)
401+
{
402+
srb.Color = color;
403+
}
398404
}
399405
break;
400406
case SelectionType.CheckBox:
401407
{
402-
if (view is SelectableCheckBox)
403-
(view as SelectableCheckBox).Color = color;
408+
if (view is SelectableCheckBox scb)
409+
{
410+
scb.Color = color;
411+
}
404412
}
405413
break;
406414
}
@@ -459,7 +467,6 @@ public class SelectableButton : Button, ISelection
459467
private bool _isSelected = false;
460468
private object _value;
461469
private Color _selectionColor = InputKitOptions.GetAccentColor();
462-
private Color _unselectedColor;
463470

464471
/// <summary>
465472
/// Default constructor
@@ -482,7 +489,6 @@ public SelectableButton(object value) : this()
482489
FontSize = GlobalSetting.FontSize;
483490
CornerRadius = (int)GlobalSetting.CornerRadius;
484491
BorderColor = GlobalSetting.BorderColor;
485-
UnselectedColor = GlobalSetting.BackgroundColor;
486492
BorderWidth = 2;
487493
Clicked += (s, args) => UpdateSelection();
488494
}
@@ -497,7 +503,10 @@ public SelectableButton(object value, SelectionView parent) : this(value)
497503
SelectedColor = parent.Color;
498504
}
499505

500-
public Color UnselectedColor { get => _unselectedColor; set { _unselectedColor = value; UpdateColors(); } }
506+
public static readonly BindableProperty UnSelectedColorProperty = BindableProperty.Create(nameof(UnselectedColor), typeof(Color), typeof(SelectableButton),
507+
defaultValue: GlobalSetting.BackgroundColor, propertyChanged: (bo, ov, nv) => (bo as SelectableButton).UpdateColors());
508+
509+
public Color UnselectedColor { get => (Color)GetValue(UnSelectedColorProperty); set => SetValue(UnSelectedColorProperty, value); }
501510

502511
public Color SelectedColor
503512
{

0 commit comments

Comments
 (0)