Skip to content

Commit

Permalink
Fix for issue xamarin#7671
Browse files Browse the repository at this point in the history
  • Loading branch information
neolithos committed May 25, 2020
1 parent 54e23c4 commit b7e17e9
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="Xamarin.Forms.Controls.Issues.Issue7671">
<ContentPage.Content>
<StackLayout>
<Label Text="Welcome to Xamarin.Forms!"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage.Content>
<ContentPage.ControlTemplate>
<ControlTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition />
</Grid.RowDefinitions>

<Frame BackgroundColor="Green">
<Label Grid.Row="0" Text="I am the template." />
</Frame>
<ContentPresenter Grid.Row="1" />
</Grid>
</ControlTemplate>
</ContentPage.ControlTemplate>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -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, "Automate GC checks of picker disposals", PlatformAffected.WPF)]
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Issue7671 : ContentPage
{
public Issue7671()
{
InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue7519Xaml.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue7671.xaml.cs">
<DependentUpon>Issue7671.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue7700.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue7758.xaml.cs">
<SubType>Code</SubType>
Expand Down Expand Up @@ -1929,6 +1933,13 @@
<Generator>MSBuild:Compile</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue7671.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</EmbeddedResource>
</ItemGroup>
</Project>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue7048.xaml">
<SubType>Designer</SubType>
Expand Down
46 changes: 26 additions & 20 deletions Xamarin.Forms.Platform.WPF/Renderers/PageRenderer.cs
Original file line number Diff line number Diff line change
@@ -1,49 +1,55 @@
using System.ComponentModel;
using System.Linq;
using Xamarin.Forms.Platform.WPF.Controls;

namespace Xamarin.Forms.Platform.WPF
{
public class PageRenderer : VisualPageRenderer<Page, FormsContentPage>
{
VisualElement _currentView;
VisualElement _currentView = null;

protected override void OnElementChanged(ElementChangedEventArgs<Page> 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);
}
} // proc OnElementChanged

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();
}
}
} // proc OnElementPropertyChanged


void UpdateContent()
private void UpdateContent()
{
ContentPage page = Element as ContentPage;
if (page != null)
if (_currentView != null) // destroy current view
{
if (_currentView != null)
{
_currentView.Cleanup(); // cleanup old view
}
_currentView?.Cleanup();
_currentView = null;
}

_currentView = page.Content;
Control.Content = _currentView != null ? Platform.GetOrCreateRenderer(_currentView).GetNativeElement() : null;
// create new view based on the first children, not content
if (Element is IElementController page)
{
_currentView = page.LogicalChildren.OfType<VisualElement>().FirstOrDefault();
if (_currentView != null)
Control.Content = Platform.GetOrCreateRenderer(_currentView).GetNativeElement();
else
Control.Content = null;
}
else
Control.Content = null;
}
}
}

0 comments on commit b7e17e9

Please sign in to comment.