void AddNativeControls(NestedNativeControlGalleryPage page) { if (page.NativeControlsAdded) { return; } StackLayout sl = page.Layout; // Create and add a native TextView var textView = new TextView(this) { Text = "I am a native TextView", TextSize = 14 }; sl?.Children.Add(textView); // Create and add a native Button var button = new global::Android.Widget.Button(this) { Text = "Click to change TextView font size" }; float originalSize = textView.TextSize; button.Click += (sender, args) => { textView.TextSize = textView.TextSize == originalSize ? 24 : 14; }; sl?.Children.Add(button.ToView()); // Create a control which we know doesn't behave correctly with regard to measurement var difficultControl0 = new BrokenNativeControl(this) { Text = "This native control doesn't play nice with sizing, which is why it's all squished to one side." }; var difficultControl1 = new BrokenNativeControl(this) { Text = "Same control, but with a custom GetDesiredSize delegate to accomodate it's sizing problems." }; // Add a misbehaving control sl?.Children.Add(difficultControl0); // Add a misbehaving control with a custom delegate for GetDesiredSize sl?.Children.Add(difficultControl1, SizeBrokenControl); page.NativeControlsAdded = true; }
void AddNativeBindings(NativeBindingGalleryPage page) { if (page.NativeControlsAdded) { return; } StackLayout sl = page.Layout; var textView = new TextView(this) { TextSize = 14, Text = "This will be text" }; var viewGroup = new LinearLayout(this); viewGroup.AddView(textView); var buttonColor = new global::Android.Widget.Button(this) { Text = "Change label Color" }; buttonColor.Click += (sender, e) => textView.SetTextColor(Color.Blue.ToAndroid()); var colorPicker = new ColorPickerView(this, 200, 200); textView.SetBinding(nameof(textView.Text), new Binding("NativeLabel")); //this doesn't work because there's not TextColor property //textView.SetBinding("TextColor", new Binding("NativeLabelColor", converter: new ColorConverter())); colorPicker.SetBinding(nameof(colorPicker.SelectedColor), new Binding("NativeLabelColor", BindingMode.TwoWay, new ColorConverter()), "ColorPicked"); sl?.Children.Add(viewGroup); sl?.Children.Add(buttonColor.ToView()); sl?.Children.Add(colorPicker); page.NativeControlsAdded = true; }