Example #1
0
        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;
        }
Example #2
0
        void AddNativeControls(NestedNativeControlGalleryPage page)
        {
            if (page.NativeControlsAdded)
            {
                return;
            }

            StackLayout sl = page.Layout;

            // Create and add a native TextBlock
            var originalText = "I am a native TextBlock";
            var textBlock    = new TextBlock
            {
                Text       = originalText,
                FontSize   = 14,
                FontFamily = new FontFamily("HelveticaNeue")
            };

            sl?.Children.Add(textBlock);

            // Create and add a native Button
            var button = new global::Windows.UI.Xaml.Controls.Button {
                Content = "Toggle Font Size", Height = 80
            };

            button.Click += (sender, args) => { textBlock.FontSize = textBlock.FontSize == 14 ? 24 : 14; };

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

            // Create a control which we know doesn't behave correctly with regard to measurement
            var difficultControl = new BrokenNativeControl
            {
                Text = "Not Sized/Arranged Properly"
            };

            var difficultControl2 = new BrokenNativeControl
            {
                Text = "Fixed"
            };

            // Add the misbehaving controls, one with a custom delegate for ArrangeOverrideDelegate
            sl?.Children.Add(difficultControl);
            sl?.Children.Add(difficultControl2,
                             arrangeOverrideDelegate: (renderer, finalSize) =>
            {
                if (finalSize.Width <= 0 || double.IsInfinity(finalSize.Width))
                {
                    return(null);
                }

                FrameworkElement frameworkElement = renderer.Control;

                frameworkElement.Measure(finalSize);

                // The broken control always tries to size itself to the screen width
                // So figure that out and we'll know how far off it's laying itself out
                Rect bounds        = ApplicationView.GetForCurrentView().VisibleBounds;
                double scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
                var screenWidth    = new Size(bounds.Width * scaleFactor, bounds.Height * scaleFactor);

                // We can re-center it by offsetting it during the Arrange call
                double diff = Math.Abs(screenWidth.Width - finalSize.Width) / -2;
                frameworkElement.Arrange(new Rect(diff, 0, finalSize.Width - diff, finalSize.Height));

                // Arranging the control to the left will make it show up past the edge of the stack layout
                // We can fix that by clipping it manually
                var clip = new RectangleGeometry {
                    Rect = new Rect(-diff, 0, finalSize.Width, finalSize.Height)
                };
                frameworkElement.Clip = clip;

                return(finalSize);
            }
                             );

            page.NativeControlsAdded = true;
        }
Example #3
0
        void AddNativeControls(NestedNativeControlGalleryPage page)
        {
            if (page.NativeControlsAdded)
            {
                return;
            }

            StackLayout sl = page.Layout;

            // Create and add a native UILabel
            var originalText = "I am a native UILabel";
            var longerText   =
                "I am a native UILabel with considerably more text. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";

            var uilabel = new UILabel
            {
                MinimumFontSize = 14f,
                Text            = originalText,
                Lines           = 0,
                LineBreakMode   = UILineBreakMode.WordWrap,
                Font            = UIFont.FromName("Helvetica", 24f)
            };

            sl?.Children.Add(uilabel);

            // Create and add a native Button
            var uibutton = new UIButton(UIButtonType.System);

            uibutton.SetTitle("Toggle Text Amount", UIControlState.Normal);
            uibutton.TitleLabel.Font = UIFont.FromName("Helvetica", 14f);


            uibutton.TouchUpInside += (sender, args) =>
            {
                uilabel.Text = uilabel.Text == originalText ? longerText : originalText;
                uilabel.SizeToFit();
            };

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

            // Create some control which we know don't behave correctly with regard to measurement
            var difficultControl0 = new BrokenNativeControl
            {
                MinimumFontSize = 14f,
                Font            = UIFont.FromName("Helvetica", 14f),
                Lines           = 0,
                LineBreakMode   = UILineBreakMode.WordWrap,
                Text            = "Doesn't play nice with sizing. That's why there's a big gap around it."
            };

            var difficultControl1 = new BrokenNativeControl
            {
                MinimumFontSize = 14f,
                Font            = UIFont.FromName("Helvetica", 14f),
                Lines           = 0,
                LineBreakMode   = UILineBreakMode.WordWrap,
                Text            = "Custom size fix specified. No gaps."
            };

            var explanation0 = new UILabel
            {
                MinimumFontSize = 14f,
                Text            = "The next control is a customized label with a bad SizeThatFits implementation.",
                Lines           = 0,
                LineBreakMode   = UILineBreakMode.WordWrap,
                Font            = UIFont.FromName("Helvetica", 24f)
            };

            var explanation1 = new UILabel
            {
                MinimumFontSize = 14f,
                Text            = "The next control is the same broken class as above, but we pass in an override to the GetDesiredSize method.",
                Lines           = 0,
                LineBreakMode   = UILineBreakMode.WordWrap,
                Font            = UIFont.FromName("Helvetica", 24f)
            };

            // Add a misbehaving control
            sl?.Children.Add(explanation0);
            sl?.Children.Add(difficultControl0);

            // Add the misbehaving control with a custom delegate for FixSize
            sl?.Children.Add(explanation1);
            sl?.Children.Add(difficultControl1, FixSize);

            page.NativeControlsAdded = true;
        }
Example #4
0
		static void AddNativeControls (NestedNativeControlGalleryPage page)
		{
			if (page.NativeControlsAdded) {
				return;
			}

			StackLayout sl = page.Layout;

			// Create and add a native TextBlock
			var originalText = "I am a native TextBlock";
			var textBlock = new TextBlock {
				Text = originalText,
				FontSize = 14,
				FontFamily = new FontFamily ("HelveticaNeue")
			};

			sl?.Children.Add (textBlock);

			// Create and add a native Button 
			var button = new global::Windows.UI.Xaml.Controls.Button { Content = "Click to toggle font size", Height = 80 };
			button.Click += (sender, args) => { textBlock.FontSize = textBlock.FontSize == 14 ? 24 : 14; };

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

			// Create a control which we know doesn't behave correctly with regard to measurement
			var difficultControl = new BrokenNativeControl {
				Text = "Not Sized/Arranged Properly"
			};

			var difficultControl2 = new BrokenNativeControl {
				Text = "Fixed"
			};

			// Add the misbehaving controls, one with a custom delegate for ArrangeOverrideDelegate
			sl?.Children.Add (difficultControl);
			sl?.Children.Add (difficultControl2,
				arrangeOverrideDelegate: (renderer, finalSize) => {
					if (finalSize.Width <= 0 || double.IsInfinity (finalSize.Width)) {
						return null;
					}

					FrameworkElement frameworkElement = renderer.Control;

					frameworkElement.Measure (finalSize);

					// The broken control tries sizes itself to be the width of the screen
					var wrongSize = Window.Current.Bounds.Width * (int)DisplayProperties.ResolutionScale / 100;

					// We can re-center it by offsetting it during the Arrange call
					double diff = Math.Abs(finalSize.Width - wrongSize) / -2;
					frameworkElement.Arrange (new Rect (diff, 0, finalSize.Width - diff, finalSize.Height));

					// Arranging the control to the left will make it show up past the edge of the stack layout
					// We can fix that by clipping it manually
					var clip = new RectangleGeometry { Rect = new Rect (-diff, 0, finalSize.Width, finalSize.Height) };
					frameworkElement.Clip = clip;

					return finalSize;
				}
			);

			page.NativeControlsAdded = true;
		}
Example #5
0
        static void AddNativeControls(NestedNativeControlGalleryPage page)
        {
            if (page.NativeControlsAdded)
            {
                return;
            }

            StackLayout sl = page.Layout;

            // Create and add a native TextBlock
            var originalText = "I am a native TextBlock";
            var textBlock    = new TextBlock {
                Text       = originalText,
                FontSize   = 14,
                FontFamily = new FontFamily("HelveticaNeue")
            };

            sl?.Children.Add(textBlock);

            // Create and add a native Button
            var button = new global::Windows.UI.Xaml.Controls.Button {
                Content = "Click to toggle font size", Height = 80
            };

            button.Click += (sender, args) => { textBlock.FontSize = textBlock.FontSize == 14 ? 24 : 14; };

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

            // Create a control which we know doesn't behave correctly with regard to measurement
            var difficultControl = new BrokenNativeControl {
                Text = "Not Sized/Arranged Properly"
            };

            var difficultControl2 = new BrokenNativeControl {
                Text = "Fixed"
            };

            // Add the misbehaving controls, one with a custom delegate for ArrangeOverrideDelegate
            sl?.Children.Add(difficultControl);
            sl?.Children.Add(difficultControl2,
                             arrangeOverrideDelegate: (renderer, finalSize) => {
                if (finalSize.Width <= 0 || double.IsInfinity(finalSize.Width))
                {
                    return(null);
                }

                FrameworkElement frameworkElement = renderer.Control;

                frameworkElement.Measure(finalSize);

                // The broken control tries sizes itself to be the width of the screen
                var wrongSize = Window.Current.Bounds.Width * (int)DisplayProperties.ResolutionScale / 100;

                // We can re-center it by offsetting it during the Arrange call
                double diff = Math.Abs(finalSize.Width - wrongSize) / -2;
                frameworkElement.Arrange(new Rect(diff, 0, finalSize.Width - diff, finalSize.Height));

                // Arranging the control to the left will make it show up past the edge of the stack layout
                // We can fix that by clipping it manually
                var clip = new RectangleGeometry {
                    Rect = new Rect(-diff, 0, finalSize.Width, finalSize.Height)
                };
                frameworkElement.Clip = clip;

                return(finalSize);
            }
                             );

            page.NativeControlsAdded = true;
        }
        void AddNativeControls(NestedNativeControlGalleryPage page)
        {
            if (page.NativeControlsAdded)
            {
                return;
            }

            StackLayout sl = page.Layout;

            // Create and add a native UILabel
            var originalText = "I am a native UILabel";
            var longerText   =
                "I am a native UILabel with considerably more text. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";

            var uilabel = new NSTextField
            {
                StringValue          = originalText,
                MaximumNumberOfLines = 0,
                LineBreakMode        = NSLineBreakMode.ByWordWrapping,
                Font = NSFont.FromFontName("Helvetica", 24f)
            };

            sl?.Children.Add(uilabel);

            // Create and add a native Button
            var uibutton = NSButtonExtensions.CreateButton("Toggle Text Amount", () =>
            {
                uilabel.StringValue = uilabel.StringValue == originalText ? longerText : originalText;
                uilabel.SizeToFit();
            });

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


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

            // Create some control which we know don't behave correctly with regard to measurement
            var difficultControl0 = new BrokenNativeControl
            {
                Font = NSFont.FromFontName("Helvetica", 14f),
                MaximumNumberOfLines = 0,
                LineBreakMode        = NSLineBreakMode.ByWordWrapping,
                StringValue          = "Doesn't play nice with sizing. That's why there's a big gap around it."
            };

            var difficultControl1 = new BrokenNativeControl
            {
                Font = NSFont.FromFontName("Helvetica", 14f),
                MaximumNumberOfLines = 0,
                LineBreakMode        = NSLineBreakMode.ByWordWrapping,
                StringValue          = "Custom size fix specified. No gaps."
            };

            var explanation0 = new NSTextField
            {
                StringValue          = "The next control is a customized label with a bad SizeThatFits implementation.",
                MaximumNumberOfLines = 0,
                LineBreakMode        = NSLineBreakMode.ByWordWrapping,
                Font = NSFont.FromFontName("Helvetica", 14f),
            };

            var explanation1 = new NSTextField
            {
                StringValue          = "The next control is the same broken class as above, but we pass in an override to the GetDesiredSize method.",
                MaximumNumberOfLines = 0,
                LineBreakMode        = NSLineBreakMode.ByWordWrapping,
                Font = NSFont.FromFontName("Helvetica", 14f),
            };

            // Add a misbehaving control
            sl?.Children.Add(explanation0);
            sl?.Children.Add(difficultControl0);

            // Add the misbehaving control with a custom delegate for FixSize
            sl?.Children.Add(explanation1);
            sl?.Children.Add(difficultControl1, FixSize);

            page.NativeControlsAdded = true;
        }