コード例 #1
0
ファイル: AppDelegate.cs プロジェクト: sung-su/maui
        void AddNativeBindings(NativeBindingGalleryPage page)
        {
            if (page.NativeControlsAdded)
            {
                return;
            }

            StackLayout sl = page.Layout;

            int width = (int)sl.Width;
            int heightCustomLabelView = 100;

            var uilabel = new UILabel(new CGRect(0, 0, width, heightCustomLabelView))
            {
#pragma warning disable CA1416 // TODO: UILabel.MinimumFontSize has [UnsupportedOSPlatform("ios6.0")]
                MinimumFontSize = 14f,
#pragma warning restore CA1416
                Lines         = 0,
                LineBreakMode = UILineBreakMode.WordWrap,
                Font          = UIFont.FromName("Helvetica", 24f),
                Text          = "DefaultText"
            };

            var uibuttonColor = new UIButton(UIButtonType.System);

            uibuttonColor.SetTitle("Toggle Text Color Binding", UIControlState.Normal);
            uibuttonColor.TitleLabel.Font = UIFont.FromName("Helvetica", 14f);
            uibuttonColor.TouchUpInside  += (sender, args) => uilabel.TextColor = UIColor.Blue;

            var nativeColorConverter = new ColorConverter();

            uilabel.SetBinding("Text", new Binding("NativeLabel"));
            uilabel.SetBinding(nameof(uilabel.TextColor), new Binding("NativeLabelColor", converter: nativeColorConverter));

            var kvoSlider = new KVOUISlider();

            kvoSlider.MaxValue = 100;
            kvoSlider.MinValue = 0;
            kvoSlider.SetBinding(nameof(kvoSlider.KVOValue), new Binding("Age", BindingMode.TwoWay));
            sl?.Children.Add(kvoSlider);

            var uiView = new UIView(new CGRect(0, 0, width, heightCustomLabelView));

            uiView.Add(uilabel);
            sl?.Children.Add(uiView);
            sl?.Children.Add(uibuttonColor.ToView());
            // TODO: Replace with a new plugin or API
            //var colorPicker = new AdvancedColorPicker.ColorPickerView(new CGRect(0, 0, width, 300));
            //colorPicker.SetBinding("SelectedColor", new Binding("NativeLabelColor", BindingMode.TwoWay, nativeColorConverter), "ColorPicked");
            //sl?.Children.Add(colorPicker);
            page.NativeControlsAdded = true;
        }
コード例 #2
0
ファイル: MainPage.xaml.cs プロジェクト: zmtzawqlp/maui
        void AddNativeBindings(NativeBindingGalleryPage page)
        {
            if (page.NativeControlsAdded)
            {
                return;
            }

            StackLayout sl = page.Layout;

            var txbLabel = new TextBlock
            {
                FontSize   = 14,
                FontFamily = new FontFamily("HelveticaNeue")
            };

            var txbBox = new TextBox
            {
                FontSize   = 14,
                FontFamily = new FontFamily("HelveticaNeue")
            };

            var btnColor = new global::Windows.UI.Xaml.Controls.Button {
                Content = "Toggle Label Color", Height = 80
            };

            btnColor.Click += (sender, args) => txbLabel.Foreground = new SolidColorBrush(global::Windows.UI.Colors.Pink);

            var btnTextBox = new global::Windows.UI.Xaml.Controls.Button {
                Content = "Change text textbox", Height = 80
            };

            btnTextBox.Click += (sender, args) => txbBox.Text = "Hello 2 way native";

            txbLabel.SetBinding("Text", new Binding("NativeLabel"));
            txbBox.SetBinding("Text", new Binding("NativeLabel", BindingMode.TwoWay), "TextChanged");
            txbLabel.SetBinding("Foreground", new Binding("NativeLabelColor", BindingMode.TwoWay, new ColorToBrushNativeBindingConverter()));

            var grd = new StackPanel();

            grd.Children.Add(txbLabel);
            grd.Children.Add(btnColor);

            sl?.Children.Add(grd.ToView());

            sl?.Children.Add(txbBox);
            sl?.Children.Add(btnTextBox.ToView());

            page.NativeControlsAdded = true;
        }
コード例 #3
0
        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;
        }
コード例 #4
0
        void AddNativeBindings(NativeBindingGalleryPage page)
        {
            if (page.NativeControlsAdded)
            {
                return;
            }

            StackLayout sl = page.Layout;

            int width = 200;
            int heightCustomLabelView = 100;

            var uilabel = new NSTextField(new CGRect(0, 0, width, heightCustomLabelView))
            {
                BackgroundColor      = NSColor.Clear,
                Editable             = false,
                Bezeled              = false,
                DrawsBackground      = false,
                MaximumNumberOfLines = 0,
                LineBreakMode        = NSLineBreakMode.ByWordWrapping,
                Font        = NSFont.FromFontName("Helvetica", 24f),
                StringValue = "DefaultText"
            };

            var uibuttonColor = NSButtonExtensions.CreateButton("Toggle Text Color Binding", () => uilabel.TextColor = NSColor.Blue);

            uibuttonColor.Font = NSFont.FromFontName("Helvetica", 14f);

            uilabel.SetBinding("StringValue", new Binding("NativeLabel"));
            uilabel.SetBinding(nameof(uilabel.TextColor), new Binding("NativeLabelColor", converter: new ColorConverter()));

            sl?.Children.Add(uilabel);
            sl?.Children.Add(uibuttonColor.ToView());
            //var colorPicker = new NSColorWell();
            //colorPicker.SetBinding("SelectedColor", new Binding("NativeLabelColor", BindingMode.TwoWay, new ColorConverter()), "ColorPicked");
            //sl?.Children.Add(colorPicker);
            page.NativeControlsAdded = true;
        }