public IndividualListCell() { var itemName = new Label { YAlign = TextAlignment.Center, FontSize = 20, TextColor = Color.Black }; itemName.SetBinding(Label.TextProperty, "ListDataItemName"); itemQuantity = new Label { HorizontalOptions = LayoutOptions.CenterAndExpand, YAlign = TextAlignment.Center, TextColor = Color.Black, FontSize = 16 }; itemQuantity.SetBinding(Label.TextProperty, "itemQuantity"); Stepper stepper = new Stepper { Minimum = 1.0, Maximum = 10.0, Increment = 1.0, HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand }; stepper.SetBinding(Stepper.ValueProperty, "itemQuantity"); stepper.ValueChanged += OnStepperValueChanged; var addToBasketButton = new Button { Text = "Add to Basket", HorizontalOptions = LayoutOptions.CenterAndExpand // VerticalOptions = LayoutOptions.FillAndExpand, }; addToBasketButton.Clicked += (sender, e) => { var item = (TapandGo.Data.ItemsListData)BindingContext; TapandGo.Database.Database.GetDatabase().TransferFromListToBasket(item.ItemId, item.ListDataItemName, item.itemQuantity, item.ListDataItemPrice, item.ListDataItemPicture, item.ListDataItemPriceString); }; var itemImage = new Image { }; itemImage.SetBinding(Image.SourceProperty, "ListDataItemPicture"); var layout = new StackLayout { Padding = new Thickness(20, 0, 0, 0), Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.StartAndExpand, Children = {itemImage, itemName, itemQuantity, stepper} }; View = layout; }
public ScaleRotate() { Label label = new Label { Text = "SCALE AND\nROTATE", HorizontalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.CenterAndExpand }; // Label and Slider for Scale property. Label scaleSliderValue = new Label { VerticalTextAlignment = TextAlignment.Center }; Grid.SetRow(scaleSliderValue, 0); Grid.SetColumn(scaleSliderValue, 0); Slider scaleSlider = new Slider { Maximum = 10 }; Grid.SetRow(scaleSlider, 0); Grid.SetColumn(scaleSlider, 1); // Set Bindings. scaleSliderValue.BindingContext = scaleSlider; scaleSliderValue.SetBinding(Label.TextProperty, new Binding("Value", BindingMode.OneWay, null, null, "Scale = {0:F1}")); scaleSlider.BindingContext = label; scaleSlider.SetBinding(Slider.ValueProperty, new Binding("Scale", BindingMode.TwoWay)); // Label and Slider for Rotation property. Label rotationSliderValue = new Label { VerticalTextAlignment = TextAlignment.Center }; Grid.SetRow(rotationSliderValue, 1); Grid.SetColumn(rotationSliderValue, 0); Slider rotationSlider = new Slider { Maximum = 360 }; Grid.SetRow(rotationSlider, 1); Grid.SetColumn(rotationSlider, 1); // Set Bindings. rotationSliderValue.BindingContext = rotationSlider; rotationSliderValue.SetBinding(Label.TextProperty, new Binding("Value", BindingMode.OneWay, null, null, "Rotation = {0:F0}")); rotationSlider.BindingContext = label; rotationSlider.SetBinding(Slider.ValueProperty, new Binding("Rotation", BindingMode.TwoWay)); // Label and Slider for AnchorX property. Label anchorxStepperValue = new Label { VerticalTextAlignment = TextAlignment.Center }; Grid.SetRow(anchorxStepperValue, 2); Grid.SetColumn(anchorxStepperValue, 0); Stepper anchorxStepper = new Stepper { Maximum = 2, Minimum = -1, Increment = 0.5 }; Grid.SetRow(anchorxStepper, 2); Grid.SetColumn(anchorxStepper, 1); // Set bindings. anchorxStepperValue.BindingContext = anchorxStepper; anchorxStepperValue.SetBinding(Label.TextProperty, new Binding("Value", BindingMode.OneWay, null, null, "AnchorX = {0:F1}")); anchorxStepper.BindingContext = label; anchorxStepper.SetBinding(Stepper.ValueProperty, new Binding("AnchorX", BindingMode.TwoWay)); // Label and Slider for AnchorY property. Label anchoryStepperValue = new Label { VerticalTextAlignment = TextAlignment.Center }; Grid.SetRow(anchoryStepperValue, 3); Grid.SetColumn(anchoryStepperValue, 0); Stepper anchoryStepper = new Stepper { Maximum = 2, Minimum = -1, Increment = 0.5 }; Grid.SetRow(anchoryStepper, 3); Grid.SetColumn(anchoryStepper, 1); // Set bindings. anchoryStepperValue.BindingContext = anchoryStepper; anchoryStepperValue.SetBinding(Label.TextProperty, new Binding("Value", BindingMode.OneWay, null, null, "AnchorY = {0:F1}")); anchoryStepper.BindingContext = label; anchoryStepper.SetBinding(Stepper.ValueProperty, new Binding("AnchorY", BindingMode.TwoWay)); // Assemble the page. Content = new StackLayout { Children = { label, new Grid { Padding = 10, RowDefinitions = { new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, }, ColumnDefinitions = { new ColumnDefinition { Width = GridLength.Auto }, new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star)} }, Children = { scaleSliderValue, scaleSlider, rotationSliderValue, rotationSlider, anchorxStepperValue, anchorxStepper, anchoryStepperValue, anchoryStepper } } } }; }
public SliderStepperSwitchBindingsPage() { // Create a Slider. Slider slider = new Slider { VerticalOptions = LayoutOptions.EndAndExpand }; // Create a Label to display the Slider value. Label sliderValueLabel = new Label { Font = Font.SystemFontOfSize(NamedSize.Large), VerticalOptions = LayoutOptions.StartAndExpand, HorizontalOptions = LayoutOptions.Center }; // Create a Stepper. Stepper stepper = new Stepper { VerticalOptions = LayoutOptions.EndAndExpand, HorizontalOptions = LayoutOptions.Center }; // Create a Label to display the Stepper value. Label stepperValueLabel = new Label { Font = Font.SystemFontOfSize(NamedSize.Large), VerticalOptions = LayoutOptions.StartAndExpand, HorizontalOptions = LayoutOptions.Center, }; // Create a Switch. Switch switcher = new Switch { IsToggled = true, VerticalOptions = LayoutOptions.EndAndExpand, HorizontalOptions = LayoutOptions.Center }; // Create a Label to display the Switch value. Label switchToggledLabel = new Label { Font = Font.SystemFontOfSize(NamedSize.Large), VerticalOptions = LayoutOptions.StartAndExpand, HorizontalOptions = LayoutOptions.Center }; // Put them all in a StackLayout. this.Content = new StackLayout { Children = { slider, sliderValueLabel, stepper, stepperValueLabel, switcher, switchToggledLabel, } }; sliderValueLabel.BindingContext = slider; sliderValueLabel.SetBinding (Label.OpacityProperty, "Value"); slider.BindingContext = switcher; slider.SetBinding (Slider.IsEnabledProperty, "IsToggled"); stepper.BindingContext = switcher; stepper.SetBinding (Stepper.IsEnabledProperty, "IsToggled"); sliderValueLabel.SetBinding (Label.TextProperty, new Binding ("Value", BindingMode.Default, null, null, "The Slider value is {0:F2}")); stepperValueLabel.BindingContext = stepper; stepperValueLabel.SetBinding (Label.TextProperty, new Binding ("Value", BindingMode.Default, null, null, "The Stepper value is {0}")); switchToggledLabel.BindingContext = switcher; switchToggledLabel.SetBinding (Label.TextProperty, new Binding ("IsToggled", BindingMode.Default, null, null, "The Switch is toggled {0}")); }
public RotationYDemoPage () { this.Title = "RotationY"; // Label to be transformed. Label label = new Label { Text = "ROTATIONY", FontSize = 50, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.CenterAndExpand }; // Label and Slider for RotationY property. Label rotationSliderValue = new Label { VerticalTextAlignment = TextAlignment.Center }; Grid.SetRow (rotationSliderValue, 0); Grid.SetColumn (rotationSliderValue, 0); Slider rotationSlider = new Slider { Maximum = 360 }; Grid.SetRow (rotationSlider, 0); Grid.SetColumn (rotationSlider, 1); // Set Bindings. rotationSliderValue.BindingContext = rotationSlider; rotationSliderValue.SetBinding (Label.TextProperty, new Binding ("Value", BindingMode.OneWay, null, null, "RotationY = {0:F0}\u00B0")); rotationSlider.BindingContext = label; rotationSlider.SetBinding (Slider.ValueProperty, new Binding ("RotationY", BindingMode.TwoWay)); // Label and Slider for AnchorX property. Label anchorxStepperValue = new Label { VerticalTextAlignment = TextAlignment.Center }; Grid.SetRow (anchorxStepperValue, 1); Grid.SetColumn (anchorxStepperValue, 0); Stepper anchorxStepper = new Stepper { Maximum = 2, Minimum = -1, Increment = 0.5 }; Grid.SetRow (anchorxStepper, 1); Grid.SetColumn (anchorxStepper, 1); // Set bindings. anchorxStepperValue.BindingContext = anchorxStepper; anchorxStepperValue.SetBinding (Label.TextProperty, new Binding ("Value", BindingMode.OneWay, null, null, "AnchorX = {0:F1}")); anchorxStepper.BindingContext = label; anchorxStepper.SetBinding (Stepper.ValueProperty, new Binding ("AnchorX", BindingMode.TwoWay)); // Label and Slider for AnchorY property. Label anchoryStepperValue = new Label { VerticalTextAlignment = TextAlignment.Center }; Grid.SetRow (anchoryStepperValue, 2); Grid.SetColumn (anchoryStepperValue, 0); Stepper anchoryStepper = new Stepper { Maximum = 2, Minimum = -1, Increment = 0.5 }; Grid.SetRow (anchoryStepper, 2); Grid.SetColumn (anchoryStepper, 1); // Set bindings. anchoryStepperValue.BindingContext = anchoryStepper; anchoryStepperValue.SetBinding (Label.TextProperty, new Binding ("Value", BindingMode.OneWay, null, null, "AnchorY = {0:F1}")); anchoryStepper.BindingContext = label; anchoryStepper.SetBinding (Stepper.ValueProperty, new Binding ("AnchorY", BindingMode.TwoWay)); // Assemble the page. this.Content = new StackLayout { Children = { label, new Grid { Padding = 10, RowDefinitions = { new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto } }, ColumnDefinitions = { new ColumnDefinition { Width = GridLength.Auto }, new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) } }, Children = { rotationSliderValue, rotationSlider, anchorxStepperValue, anchorxStepper, anchoryStepperValue, anchoryStepper } } } }; }
public BasketPageCell() { var itemName = new Label { YAlign = TextAlignment.Center, FontSize = 20, TextColor = Color.Black }; itemName.SetBinding(Label.TextProperty, "BasketItemName"); Button deleteButton = new Button { Text = "Delete" }; deleteButton.Clicked += (sender, e) => { var item = (TapandGo.Data.ShoppingBasketData)BindingContext; TapandGo.Database.Database.GetDatabase().DeleteItemFromBasket(item.ShoppingBasketId); ShoppingCart.Refresh(); }; Stepper stepper = new Stepper { Minimum = 0.0, Maximum = 10.0, Increment = 1.0, HorizontalOptions = LayoutOptions.CenterAndExpand }; stepper.SetBinding(Stepper.ValueProperty, "BasketItemQuantity"); // stepper.ValueChanged += OnStepperValueChanged; var itemPrice = new Label { HorizontalOptions = LayoutOptions.CenterAndExpand, YAlign = TextAlignment.Center, TextColor = Color.Black }; itemPrice.SetBinding(Label.TextProperty, "BasketItemPriceString"); var itemQuantity = new Entry { HorizontalOptions = LayoutOptions.CenterAndExpand, // YAlign = TextAlignment.Center, TextColor = Color.Black, }; itemQuantity.SetBinding(Entry.TextProperty, "BasketItemQuantity"); itemQuantity.Keyboard = Keyboard.Numeric; int lastQuantity = Convert.ToInt32 ( itemQuantity.Text ); itemQuantity.Completed += (sender, e) => { var i = itemQuantity.Text; int quantity = Convert.ToInt32(i); var item = (TapandGo.Data.ShoppingBasketData)BindingContext; int id = item.BasketItemID; int basketID = item.ShoppingBasketId; string newItemName = item.BasketItemName; double newItemPrice = item.BasketItemPrice; string itemPriceString = item.BasketItemPriceString; string itemPicture = item.BasketItemPicture; Database.Database.GetDatabase().UpdateBasketItemQuantity(quantity, id, newItemName, newItemPrice, itemPriceString, itemPicture, basketID); ShoppingCart.totalPrice.Text = "Total: $" + Database.Database.GetDatabase().GetTotalPrice().ToString() + ".00"; }; var itemImage = new Image { }; itemImage.SetBinding(Image.SourceProperty, "BasketItemPicture"); var layout = new StackLayout { Padding = new Thickness(20, 0, 0, 0), Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.StartAndExpand, Children = {itemImage, itemName, itemQuantity, itemPrice, deleteButton} }; View = layout; }