void OnThumbRadiusSwitchToggled(object?sender, ToggledEventArgs e) { if (sender == LowerUpperThumbRadiusSwitch) { if (e.Value) { RangeSlider.SetBinding(RangeSlider.LowerThumbRadiusProperty, GetSliderValueBinding(LowerThumbRadiusSlider)); RangeSlider.SetBinding(RangeSlider.UpperThumbRadiusProperty, GetSliderValueBinding(UpperThumbRadiusSlider)); return; } RangeSlider.LowerThumbRadius = (double)RangeSlider.LowerThumbRadiusProperty.DefaultValue; RangeSlider.UpperThumbRadius = (double)RangeSlider.UpperThumbRadiusProperty.DefaultValue; return; } if (sender == ThumbRadiusSwitch) { if (e.Value) { RangeSlider.SetBinding(RangeSlider.ThumbRadiusProperty, GetSliderValueBinding(ThumbRadiusSlider)); OnThumbRadiusSwitchToggled(LowerUpperThumbRadiusSwitch, new ToggledEventArgs(LowerUpperThumbRadiusSwitch.IsToggled)); return; } RangeSlider.ThumbRadius = (double)RangeSlider.ThumbRadiusProperty.DefaultValue; OnThumbRadiusSwitchToggled(LowerUpperThumbRadiusSwitch, new ToggledEventArgs(false)); return; } }
void OnTrackRadiusSwitchToggled(object?sender, ToggledEventArgs e) { if (e.Value) { RangeSlider.SetBinding(RangeSlider.TrackRadiusProperty, GetSliderValueBinding(TrackRadiusSlider)); return; } RangeSlider.TrackRadius = (double)RangeSlider.TrackRadiusProperty.DefaultValue; }
void OnThumbSizeSwitchToggled(object sender, ToggledEventArgs e) { if (e.Value) { RangeSlider.SetBinding(RangeSlider.LowerThumbSizeProperty, GetSliderValueBinding(LowerThumbSizeSlider)); RangeSlider.SetBinding(RangeSlider.UpperThumbSizeProperty, GetSliderValueBinding(UpperThumbSizeSlider)); return; } RangeSlider.LowerThumbSize = (double)RangeSlider.LowerThumbSizeProperty.DefaultValue; RangeSlider.UpperThumbSize = (double)RangeSlider.UpperThumbSizeProperty.DefaultValue; }
/// <summary> /// /// </summary> /// <param name="targetType"></param> public SleepSliderView(TargetType targetType) { SetBinding(ContentView.BackgroundColorProperty, new Binding("BackgroundColor")); BindingContext = new { BackgroundColor = StyledBackground }; TargetType = targetType; RangeSlider = new RangeSlider(); RangeSlider.SetBinding(RangeSlider.BackgroundColorProperty, new Binding("BackgroundColor")); RangeSlider.SetBinding(RangeSlider.TextColorProperty, new Binding("TextColor")); RangeSlider.BindingContext = new { BackgroundColor = StyledBackground, TextColor = StyledText }; RangeSlider.MinimumValue = 0; RangeSlider.LowerValue = DefaultStart; RangeSlider.MaximumValue = 1440; RangeSlider.UpperValue = DefaultStart + DefaultSpan; RangeSlider.StepValue = 1; RangeSlider.VerticalOptions = LayoutOptions.Center; RangeSlider.TextSize = Device.GetNamedSize(NamedSize.Default, typeof(Label)); RangeSlider.FormatLabel = ViewTools.FormatDateLabel; RangeSlider.ShowTextAboveThumbs = true; Content = new StackLayout() { Spacing = 0, Padding = new Thickness(10, 0, 0, 0), VerticalOptions = LayoutOptions.CenterAndExpand, Children = { RangeSlider } }; }
private FrameworkElement OnGeneratingControl(Controllable control, ControlItem item) { FrameworkElement result = null; GeneratingControl?.Invoke(this, control, item, ref result); if (result != null) { return(result); } if (item.Type == ControlItem.PropType.Enum) { var cbox = new ComboBox { ItemsSource = item.Cookie as string[] }; cbox.SetBinding(ComboBox.SelectedItemProperty, CreateControlItemBinding(control, item)); return(cbox); } if (item.ValType == typeof(string)) { if (item.Type == ControlItem.PropType.LongText) { var btn = new Button { Content = "查看" }; btn.Click += (o, e) => { control.DoGetMember(item.Id, out object txt); new TextDialog(txt as string, $"{control.ToString()} --- {item.Name}").Show(); e.Handled = true; }; return(btn); } { var tbox = new TextBox { VerticalAlignment = VerticalAlignment.Center }; tbox.SetBinding(TextBox.TextProperty, CreateControlItemBinding(control, item)); tbox.IsReadOnly = !item.Access.HasFlag(ControlItem.PropAccess.Write); return(tbox); } } if (item.ValType == typeof(Vector2)) { var limit = (Vector2)item.Cookie; var slider = new RangeSlider { AutoToolTipPlacement = AutoToolTipPlacement.TopLeft, AutoToolTipPrecision = 3, Minimum = limit.X, Maximum = limit.Y }; slider.SetBinding(RangeSlider.LowerValueProperty, CreateControlItemBinding(control, item, new TwoWayValueConvertor( o => ((Vector2)o).X, o => new Vector2(Convert.ToSingle(o), (float)slider.HigherValue)) )); slider.SetBinding(RangeSlider.HigherValueProperty, CreateControlItemBinding(control, item, new TwoWayValueConvertor( o => ((Vector2)o).Y, o => new Vector2((float)slider.LowerValue, Convert.ToSingle(o))) )); return(slider); } if (item.ValType == typeof(Color)) { var clrPicker = new ColorPicker() { ColorMode = ColorMode.ColorCanvas }; clrPicker.SetBinding(ColorPicker.SelectedColorProperty, CreateControlItemBinding(control, item)); return(clrPicker); } if (item.ValType == typeof(float)) { if (item.Cookie == null) { var spiner = new DoubleUpDown { FormatString = "F2", Increment = 0.1 }; spiner.SetBinding(DoubleUpDown.ValueProperty, CreateControlItemBinding(control, item, ConvertorForceSingle)); return(spiner); } else { var limit = (Vector2)item.Cookie; var slider = new Slider { AutoToolTipPlacement = AutoToolTipPlacement.TopLeft, AutoToolTipPrecision = 3, Minimum = limit.X, Maximum = limit.Y }; slider.SetBinding(Slider.ValueProperty, CreateControlItemBinding(control, item, ConvertorForceSingle)); return(slider); } } if (item.ValType == typeof(ushort)) { if (item.Cookie == null) { var spiner = new IntegerUpDown { Increment = 1 }; spiner.SetBinding(IntegerUpDown.ValueProperty, CreateControlItemBinding(control, item, ConvertorForceUShort)); return(spiner); } else { dynamic limit = item.Cookie; var slider = new Slider { AutoToolTipPlacement = AutoToolTipPlacement.TopLeft, Minimum = limit.Item1, Maximum = limit.Item2 }; slider.SetBinding(Slider.ValueProperty, CreateControlItemBinding(control, item, ConvertorForceUShort)); return(slider); } } if (item.ValType == typeof(int)) { if (item.Cookie == null) { var spiner = new IntegerUpDown { Increment = 1 }; spiner.SetBinding(IntegerUpDown.ValueProperty, CreateControlItemBinding(control, item)); return(spiner); } else { dynamic limit = item.Cookie; var slider = new Slider { AutoToolTipPlacement = AutoToolTipPlacement.TopLeft, Minimum = limit.Item1, Maximum = limit.Item2 }; slider.SetBinding(Slider.ValueProperty, CreateControlItemBinding(control, item, ConvertorForceInt)); return(slider); } } if (item.ValType == typeof(bool)) { var ckBox = new CheckBox { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }; ckBox.SetBinding(CheckBox.IsCheckedProperty, CreateControlItemBinding(control, item)); return(ckBox); } { var tblock = new TextBlock { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }; tblock.SetBinding(TextBlock.TextProperty, CreateControlItemBinding(control, item)); return(tblock); } }