From ee3c84f05175934a9d847a3d867e370c4b301a99 Mon Sep 17 00:00:00 2001 From: Samantha Houts Date: Tue, 27 Sep 2016 11:12:49 -0700 Subject: [Win] Will arrange native children of custom renderers (opt-in) (#322) * Add repro for 42602 * [Win] Add option to arrange native children * [Win] Don't allocate arrangedChildren unless required --- .../CustomRenderers.cs | 57 ++++++++++++++++++++++ .../Xamarin.Forms.ControlGallery.Windows.csproj | 1 + 2 files changed, 58 insertions(+) create mode 100644 Xamarin.Forms.ControlGallery.Windows/CustomRenderers.cs (limited to 'Xamarin.Forms.ControlGallery.Windows') diff --git a/Xamarin.Forms.ControlGallery.Windows/CustomRenderers.cs b/Xamarin.Forms.ControlGallery.Windows/CustomRenderers.cs new file mode 100644 index 00000000..391aed2e --- /dev/null +++ b/Xamarin.Forms.ControlGallery.Windows/CustomRenderers.cs @@ -0,0 +1,57 @@ +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Media; +using Windows.UI.Xaml.Shapes; +using Xamarin.Forms.Platform.WinRT; + +[assembly: ExportRenderer(typeof(Xamarin.Forms.Controls.Bugzilla42602.TextBoxView), typeof(Xamarin.Forms.ControlGallery.Windows.TextBoxViewRenderer))] +namespace Xamarin.Forms.ControlGallery.Windows +{ + public class TextBoxViewRenderer : BoxViewRenderer + { + Canvas m_Canvas; + + protected override void OnElementChanged(ElementChangedEventArgs e) + { + base.OnElementChanged(e); + + ArrangeNativeChildren = true; + + if (m_Canvas != null) + Children.Remove(m_Canvas); + + m_Canvas = new Canvas() + { + Width = 200, + Height = 200, + Background = new SolidColorBrush(global::Windows.UI.Color.FromArgb(0, 255, 255, 255)), + IsHitTestVisible = false + }; + + Children.Add(m_Canvas); + + //ellipse + Shape ellipse = new Ellipse() + { + Width = 100, + Height = 100, + Fill = new SolidColorBrush(global::Windows.UI.Color.FromArgb(255, 255, 0, 0)), + + }; + Canvas.SetLeft(ellipse, 0); + Canvas.SetTop(ellipse, 0); + m_Canvas.Children.Add(ellipse); + + //text + TextBlock text = new TextBlock() + { + FontSize = 50, + FontWeight = global::Windows.UI.Text.FontWeights.Normal, + Text = "hello world", + Foreground = new SolidColorBrush(global::Windows.UI.Color.FromArgb(255, 255, 0, 0)) + }; + Canvas.SetLeft(text, 0); + Canvas.SetTop(text, 150); + m_Canvas.Children.Add(text); + } + } +} diff --git a/Xamarin.Forms.ControlGallery.Windows/Xamarin.Forms.ControlGallery.Windows.csproj b/Xamarin.Forms.ControlGallery.Windows/Xamarin.Forms.ControlGallery.Windows.csproj index aa8f862f..6252820b 100644 --- a/Xamarin.Forms.ControlGallery.Windows/Xamarin.Forms.ControlGallery.Windows.csproj +++ b/Xamarin.Forms.ControlGallery.Windows/Xamarin.Forms.ControlGallery.Windows.csproj @@ -141,6 +141,7 @@ + MainPage.xaml -- cgit v1.2.3