private static void fontAttributesPropertyChanged(BindableObject bindable, object oldValue, object newValue) { BindableMultiSelectGroupView target = bindable as BindableMultiSelectGroupView; foreach (BindableMultiSelect btn in target.radioButtons) { btn.FontAttributes = newValue.ToString(); } }
private static void labelMarginPropertyPropertyChanged(BindableObject bindable, object oldValue, object newValue) { BindableMultiSelectGroupView target = bindable as BindableMultiSelectGroupView; foreach (BindableMultiSelect btn in target.radioButtons) { btn.LabelMargin = newValue.ToString(); } }
private static void CheckBoxColorPropertyChanged(BindableObject bindable, object oldValue, object newValue) { BindableMultiSelectGroupView target = bindable as BindableMultiSelectGroupView; foreach (BindableMultiSelect btn in target.radioButtons) { btn.CheckBoxColor = (Xamarin.Forms.Color)newValue; } }
private static void fontSizePropertyChanged(BindableObject bindable, object oldValue, object newValue) { BindableMultiSelectGroupView target = bindable as BindableMultiSelectGroupView; if (double.TryParse(newValue.ToString(), out double tmp)) { foreach (BindableMultiSelect btn in target.radioButtons) { btn.FontSize = tmp; } } }
private static void displayPathChanged(BindableObject bindable, object oldValue, object newValue) { BindableMultiSelectGroupView target = bindable as BindableMultiSelectGroupView; if (target.radioButtons == null) { return; } foreach (var item in target.radioButtons) { string displayPath = newValue.ToString(); item.SetTextBinding(displayPath); } }
private static void sSetGroupViewUIProperty(BindableMultiSelectGroupView view) { if (view.radioButtons == null || view.radioButtons.Count <= 0) { return; } foreach (var rad in view.radioButtons) { if (view.DisplayPath.IsNullOrWhiteSpace() == false) { rad.SetTextBinding(view.DisplayPath); } if (view.CheckBoxColor != Color.Transparent) { rad.CheckBoxColor = view.CheckBoxColor; } if (view.TextColor != Xamarin.Forms.Color.Transparent) { rad.TextColor = view.TextColor; } if (view.CheckBoxMargin.IsNullOrWhiteSpace() == false) { rad.CheckBoxMargin = view.CheckBoxMargin; } if (view.LabelMargin.IsNullOrWhiteSpace() == false) { rad.LabelMargin = view.LabelMargin; } if (view.FontAttributes.IsNullOrWhiteSpace() == false) { rad.FontAttributes = view.FontAttributes; } if (view.FontSize > 0) { rad.FontSize = view.FontSize; } } }
private static void selectedTextsPropertyChanged(BindableObject bindable, object oldValue, object newValue) { BindableMultiSelectGroupView group = bindable as BindableMultiSelectGroupView; // 处理首次来自XAML的赋值 if (oldValue == null && (newValue is string)) { if (group.radioButtons != null && group.radioButtons.Count > 0) { List <string> temp = JsonUtils.DeserializeObject <List <string> >(group.SelectedTexts.ToString()); group.radioButtons .Where(i => temp.Contains(i.Text)) .ToList() .ForEach(i => i.IsChecked = true); } } }
private static void selectedNosPropertyChanged(BindableObject bindable, object oldValue, object newValue) { BindableMultiSelectGroupView group = bindable as BindableMultiSelectGroupView; // 处理首次来自XAML的赋值 if (oldValue == null && newValue is string) { string temp = newValue as string; try { List <int> noList = Util.JsonUtils.DeserializeObject <List <int> >(temp); if (group.radioButtons != null && group.radioButtons.Count > 0) { foreach (int no in noList) { if (no > group.radioButtons.Count) { string msg = $"{0}"; System.Diagnostics.Debug.WriteLine(msg); System.Diagnostics.Debugger.Break(); } else { var index = no - 1; group.radioButtons[index].IsChecked = true; } } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"转换{ex.GetFullInfo()}"); System.Diagnostics.Debugger.Break(); } } }
private static void ItemsSourcePropertyChanged(BindableObject bindable, IEnumerable oldValue, IEnumerable newValue) { BindableMultiSelectGroupView group = bindable as BindableMultiSelectGroupView; group.radioButtons.Clear(); group.Children.Clear(); // StackLayout if (newValue != null) { int radIndex = 0; foreach (var item in newValue) { var rad = new BindableMultiSelect(); rad.Id = radIndex; rad.BindingContext = item; rad.CheckedChanged += group.OnCheckedChanged; group.radioButtons.Add(rad); group.Children.Add(rad); // StackLayout radIndex++; } sSetGroupViewUIProperty(group); #region 设置默认选中项 if (group.SelectedTexts != null) { List <string> temp = JsonUtils.DeserializeObject <List <string> >(group.SelectedTexts.ToString()); group.radioButtons .Where(i => temp.Contains(i.Text)) .ToList() .ForEach(i => i.IsChecked = true); } else if (group.SelectedNos != null) { List <int> noList = null; try { noList = JsonUtils.DeserializeObject <List <int> >(group.SelectedNos.ToString()); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"转换{ex.GetFullInfo()}"); System.Diagnostics.Debugger.Break(); } foreach (int no in noList) { if (no > group.radioButtons.Count) { string msg = $"{0}"; System.Diagnostics.Debug.WriteLine(msg); System.Diagnostics.Debugger.Break(); } else { int index = no - 1; group.radioButtons[index].IsChecked = true; } } } #endregion } }