From 4be8ddbea3e005a56ef82cbe989f7f0b21823dff Mon Sep 17 00:00:00 2001 From: neolithos Date: Wed, 25 Sep 2019 15:05:15 +0200 Subject: [PATCH 1/4] Fix for issue #7671 Style issues Layout was applied on the content and not the visual first child Fix: typo Shared project fix Xml-Tag Fix for issue #7671 Style issues Layout was applied on the content and not the visual first child Fix: typo --- .../Issue7671.xaml | 34 +++++++++++++++++++ .../Issue7671.xaml.cs | 24 +++++++++++++ ...rin.Forms.Controls.Issues.Shared.projitems | 21 ++++++++++++ .../Controls/FormsContentPage.cs | 12 +++++-- .../FormsContentLoader.cs | 3 +- .../Renderers/PageRenderer.cs | 28 +++++++-------- 6 files changed, 105 insertions(+), 17 deletions(-) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7671.xaml create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7671.xaml.cs diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7671.xaml b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7671.xaml new file mode 100644 index 00000000000..5922a5fe235 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7671.xaml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7671.xaml.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7671.xaml.cs new file mode 100644 index 00000000000..a8b64a94d13 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7671.xaml.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Xamarin.Forms; +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; +using Xamarin.Forms.Xaml; + +namespace Xamarin.Forms.Controls.Issues +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.None, 7671, "Check ControlTemplate rendering", PlatformAffected.WPF)] + [XamlCompilation(XamlCompilationOptions.Compile)] + public partial class Issue7671 : ContentPage + { + public Issue7671() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index 1f2b93d033b..b6b192df5fa 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -287,6 +287,14 @@ Code + + Issue7671.xaml + Code + + + Issue7671.xaml + Code + Code @@ -2714,6 +2722,19 @@ MSBuild:UpdateDesignTimeXaml + + + Designer + MSBuild:Compile + + + + + + Designer + MSBuild:Compile + + Designer diff --git a/Xamarin.Forms.Platform.WPF/Controls/FormsContentPage.cs b/Xamarin.Forms.Platform.WPF/Controls/FormsContentPage.cs index be680e3d9c8..4e3c372aab4 100644 --- a/Xamarin.Forms.Platform.WPF/Controls/FormsContentPage.cs +++ b/Xamarin.Forms.Platform.WPF/Controls/FormsContentPage.cs @@ -1,10 +1,18 @@ -namespace Xamarin.Forms.Platform.WPF.Controls +using System; +using System.Windows; +using WpfSize = System.Windows.Size; + +namespace Xamarin.Forms.Platform.WPF.Controls { public class FormsContentPage : FormsPage { public FormsContentPage() { - this.DefaultStyleKey = typeof(FormsContentPage); + } + + static FormsContentPage() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(FormsContentPage), new FrameworkPropertyMetadata(typeof(FormsContentPage))); } } } diff --git a/Xamarin.Forms.Platform.WPF/FormsContentLoader.cs b/Xamarin.Forms.Platform.WPF/FormsContentLoader.cs index 3a27a89718d..a6627305dc3 100644 --- a/Xamarin.Forms.Platform.WPF/FormsContentLoader.cs +++ b/Xamarin.Forms.Platform.WPF/FormsContentLoader.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Threading; using System.Threading.Tasks; using System.Windows; @@ -57,7 +58,7 @@ private object CreateOrResizeContent(FrameworkElement parent, VisualElement visu var contentPage = visualElement as ContentPage; if (contentPage?.ControlTemplate != null) { - contentPage.Content?.Layout(actualRect); + (contentPage.LogicalChildren.OfType().FirstOrDefault() ?? contentPage.Content)?.Layout(actualRect); } else { diff --git a/Xamarin.Forms.Platform.WPF/Renderers/PageRenderer.cs b/Xamarin.Forms.Platform.WPF/Renderers/PageRenderer.cs index 47f1583df99..bb44e0ef02d 100644 --- a/Xamarin.Forms.Platform.WPF/Renderers/PageRenderer.cs +++ b/Xamarin.Forms.Platform.WPF/Renderers/PageRenderer.cs @@ -1,49 +1,49 @@ using System.ComponentModel; +using System.Linq; using Xamarin.Forms.Platform.WPF.Controls; namespace Xamarin.Forms.Platform.WPF { public class PageRenderer : VisualPageRenderer { - VisualElement _currentView; + VisualElement _currentView = null; protected override void OnElementChanged(ElementChangedEventArgs e) { if (e.NewElement != null) { - if (Control == null) // construct and SetNativeControl and suscribe control event - { + if (Control == null) SetNativeControl(new FormsContentPage()); - } - // Update control property UpdateContent(); } - base.OnElementChanged(e); } protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); - - if (e.PropertyName == ContentPage.ContentProperty.PropertyName) + + if (e.PropertyName == ContentPage.ContentProperty.PropertyName + || e.PropertyName == TemplatedPage.ControlTemplateProperty.PropertyName) + { UpdateContent(); + } } void UpdateContent() { - ContentPage page = Element as ContentPage; - if (page != null) + if (Element is ContentPage page) { - if (_currentView != null) + if (_currentView != null) // destroy current view { - _currentView.Cleanup(); // cleanup old view + _currentView?.Cleanup(); + _currentView = null; } - _currentView = page.Content; + _currentView = page.LogicalChildren.OfType().FirstOrDefault() ?? page.Content; Control.Content = _currentView != null ? Platform.GetOrCreateRenderer(_currentView).GetNativeElement() : null; } } } -} +} \ No newline at end of file From 4fb2749326e2a1276c22b98c11eaf149a1597a07 Mon Sep 17 00:00:00 2001 From: neolithos Date: Mon, 25 May 2020 23:17:13 +0200 Subject: [PATCH 2/4] Fix: Project after merge --- .../Xamarin.Forms.Controls.Issues.Shared.projitems | 1 - 1 file changed, 1 deletion(-) diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index b6b192df5fa..31f6ebe2d84 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -2728,7 +2728,6 @@ MSBuild:Compile - Designer From 5dc675293071886f2968e3d412f6f91ea5a92648 Mon Sep 17 00:00:00 2001 From: neolithos Date: Mon, 25 May 2020 23:20:32 +0200 Subject: [PATCH 3/4] Fix: Merge fragments --- .../Xamarin.Forms.Controls.Issues.Shared.projitems | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index 31f6ebe2d84..3197fc6f76d 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -291,10 +291,6 @@ Issue7671.xaml Code - - Issue7671.xaml - Code - Code @@ -2728,12 +2724,6 @@ MSBuild:Compile - - - Designer - MSBuild:Compile - - Designer From d9e2ed3ff810b5ae153c02c78c87f8bbd1c6d1a8 Mon Sep 17 00:00:00 2001 From: Gerald Versluis Date: Tue, 16 Nov 2021 14:12:13 +0100 Subject: [PATCH 4/4] Fix build --- .../Issue7671.xaml.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7671.xaml.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7671.xaml.cs index a8b64a94d13..43b4093ff8f 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7671.xaml.cs +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7671.xaml.cs @@ -1,11 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -using Xamarin.Forms; -using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.CustomAttributes; using Xamarin.Forms.Internals; using Xamarin.Forms.Xaml; @@ -13,12 +6,16 @@ namespace Xamarin.Forms.Controls.Issues { [Preserve(AllMembers = true)] [Issue(IssueTracker.None, 7671, "Check ControlTemplate rendering", PlatformAffected.WPF)] +#if APP [XamlCompilation(XamlCompilationOptions.Compile)] +#endif public partial class Issue7671 : ContentPage { public Issue7671() { +#if APP InitializeComponent(); +#endif } } } \ No newline at end of file