public View UpdateAttributesUI(ComosWebSDK.UI.UICheckBox ui) { StackLayout layout = new StackLayout() { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand }; if (!ui.ReadOnly) { editablevalues.Add(ui); } Converters.TextToBoolean c = new Converters.TextToBoolean(); if (ui.CachedValue == null) { ui.CachedValue = ui.Value.ToString(); } bool cachedvalue = (bool)c.Convert(ui.CachedValue, null, null, null); bool value = (bool)c.Convert(ui.Value, null, null, null); if ((cachedvalue != value) && (ui.CachedValue != "")) { value = cachedvalue; CheckValue(ui.NestedName, ui.CachedValue, c.ConvertBack(value, null, null, null).ToString(), ui.Text); } Switch elm = new Switch() { IsToggled = value, BindingContext = ui, IsEnabled = !ui.ReadOnly, HorizontalOptions = LayoutOptions.Fill, }; // color? //if (value != ui.Value) // elm.BackgroundColor = Color.Blue; var lbl = new Label() { HorizontalTextAlignment = TextAlignment.Start, VerticalTextAlignment = TextAlignment.Center, WidthRequest = App.WidthPixels / 3, }; lbl.Text = ui.Text; elm.Toggled += SwitchToggled; layout.Children.Add(lbl); layout.Children.Add(elm); AbsoluteLayout.SetLayoutBounds(layout, new Rectangle( ui.x, ui.y, ui.width, ui.height)); return(layout); }
public void SwitchToggled(object sender, ToggledEventArgs e) { Switch ctrl = (Switch)sender; ComosWebSDK.UI.UICheckBox b = (ComosWebSDK.UI.UICheckBox)ctrl.BindingContext; IBRServiceContracts.CWriteValue value = null; if (!Values.TryGetValue(b.NestedName, out value)) { value = new IBRServiceContracts.CWriteValue() { NestedName = b.NestedName, NewValue = e.Value ? "1" : "0", OldValue = b.Value ? "1" : "0", }; Values.Add(b.NestedName, value); } else { value.NewValue = e.Value ? "1" : "0"; } CheckValue(b.NestedName, value.NewValue, value.OldValue, b.Text); }