Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix selectionview radiobutton & checkbox usage #335

Merged
merged 1 commit into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/InputKit.Maui/Shared/Controls/RadioButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class RadioButton : StatefulStackLayout
LineBreakMode = LineBreakMode.WordWrap
};
private bool _isDisabled;
const double DOT_FULL_SCALE = .65;
protected const double DOT_FULL_SCALE = .65;
#endregion

#region Ctor
Expand Down Expand Up @@ -262,7 +262,7 @@ private protected virtual void UpdateShape()
iconChecked.Data = SelectedIconGeomerty;
}

void UpdateColors()
protected void UpdateColors()
{
iconChecked.Fill = Color;
iconCircle.Stroke = IsChecked ? Color : CircleColor;
Expand Down
42 changes: 35 additions & 7 deletions src/InputKit.Maui/Shared/Controls/SelectionView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,23 @@ public LabelPosition LabelPosition
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create(nameof(ItemsSource), typeof(IList), typeof(SelectionView), null, propertyChanged: (bo, ov, nv) => (bo as SelectionView).SetItemsSource((IList)nv));
public static readonly BindableProperty DisabledSourceProperty = BindableProperty.Create(nameof(DisabledSource), typeof(IList), typeof(SelectionView), null, propertyChanged: (bo, ov, nv) => (bo as SelectionView).UpdateView());
public static readonly BindableProperty SelectedItemProperty = BindableProperty.Create(nameof(SelectedItem), typeof(object), typeof(SelectionView), null, BindingMode.TwoWay, propertyChanged: (bo, ov, nv) => (bo as SelectionView).SetSelectedItem(nv));
public static readonly BindableProperty SelectedItemProperty = BindableProperty.Create(nameof(SelectedItem), typeof(object), typeof(SelectionView), null, BindingMode.TwoWay,
propertyChanged: (bo, ov, nv) =>
{
if (ov != nv)
{
(bo as SelectionView).SetSelectedItem(nv);
}
});
public static readonly BindableProperty SelectedItemsProperty = BindableProperty.Create(nameof(SelectedItems), typeof(IList), typeof(SelectionView), null, BindingMode.TwoWay, propertyChanged: (bo, ov, nv) => (bo as SelectionView).SetSelectedItems((IList)nv));
public static readonly BindableProperty SelectedIndexProperty = BindableProperty.Create(nameof(SelectedIndex), typeof(int), typeof(SelectionView), -1, BindingMode.TwoWay, propertyChanged: (bo, ov, nv) => (bo as SelectionView).SelectedIndex = (int)nv);
public static readonly BindableProperty SelectedIndexProperty = BindableProperty.Create(nameof(SelectedIndex), typeof(int), typeof(SelectionView), -1, BindingMode.TwoWay,
propertyChanged: (bo, ov, nv) =>
{
if (ov != nv)
{
(bo as SelectionView).SelectedIndex = (int)nv;
}
});
public static readonly BindableProperty SelectedIndexesProperty = BindableProperty.Create(nameof(SelectedIndexes), typeof(IEnumerable<int>), typeof(SelectionView), new int[0], BindingMode.TwoWay, propertyChanged: (bo, ov, nv) => (bo as SelectionView).SelectedIndexes = (IEnumerable<int>)nv);
public static new readonly BindableProperty BackgroundColorProperty = BindableProperty.Create(nameof(BackgroundColor), typeof(Color), typeof(SelectionView), GlobalSetting.BackgroundColor, propertyChanged: (bo, ov, nv) => (bo as SelectionView).BackgroundColor = (Color)nv);
public static readonly BindableProperty LabelPositionProperty = BindableProperty.Create(
Expand Down Expand Up @@ -268,7 +282,7 @@ private void Element_Clicked(object sender, EventArgs e)
{
if ((int)SelectionType % 2 == 0)
{
if (sender is ISelection selection)
if (sender is ISelection selection && selection.IsSelected)
{
if (selection.IsSelected)
{
Expand All @@ -293,9 +307,9 @@ private void Element_Clicked(object sender, EventArgs e)
}
else
{
if (sender is ISelection selection)
if (sender is ISelection selection && selection.IsSelected)
{
SetValue(SelectedItemProperty, selection.Value);
SelectedItem = selection.Value;
SetValue(SelectedIndexProperty, ItemsSource.IndexOf(selection.Value));
}
}
Expand Down Expand Up @@ -398,8 +412,13 @@ private void SetSelectedItem(object value)
private void SetSelectedItems(IList value)
{
foreach (var item in Children)
{
if (item is ISelection selection && value != null)
(item as ISelection).IsSelected = value.Contains(selection.Value);
{

selection.IsSelected = value.Contains(selection.Value);
}
}

if (value is INotifyCollectionChanged observable)
observable.CollectionChanged += SelectedItemsChanged;
Expand Down Expand Up @@ -568,7 +587,16 @@ public SelectableRadioButton(object value, Color color) : this(value)
/// <summary>
/// ISelection interface property
/// </summary>
public bool IsSelected { get => IsChecked; set => IsChecked = value; }
public bool IsSelected
{
get => IsChecked; set
{
if (IsChecked != value)
{
IsChecked = value;
}
}
}
}

/// <summary>
Expand Down