Skip to content

Commit

Permalink
Fix for issue xamarin#7671
Browse files Browse the repository at this point in the history
Style issues

Layout was applied on the content and not the visual first child

Fix: typo

Shared project fix Xml-Tag

Fix for issue xamarin#7671

Style issues

Layout was applied on the content and not the visual first child

Fix: typo
  • Loading branch information
neolithos authored and jfversluis committed Nov 16, 2021
1 parent a7b30d8 commit 4be8ddb
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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="60" />
<RowDefinition />
<RowDefinition Height="60" />
</Grid.RowDefinitions>

<Frame Grid.Row="0" BackgroundColor="Green">
<Label Text="I am the template." />
</Frame>
<ContentPresenter Grid.Row="1" />
<Frame Grid.Row="2" BackgroundColor="Red">
<Label Text="I am the template." />
</Frame>
</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, "Check ControlTemplate rendering", 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 @@ -287,6 +287,14 @@
<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)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 @@ -2714,6 +2722,19 @@
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue7671.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</EmbeddedResource>
</ItemGroup>
</Project>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue7671.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue7048.xaml">
<SubType>Designer</SubType>
Expand Down
12 changes: 10 additions & 2 deletions Xamarin.Forms.Platform.WPF/Controls/FormsContentPage.cs
Original file line number Diff line number Diff line change
@@ -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)));
}
}
}
3 changes: 2 additions & 1 deletion Xamarin.Forms.Platform.WPF/FormsContentLoader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
Expand Down Expand Up @@ -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<VisualElement>().FirstOrDefault() ?? contentPage.Content)?.Layout(actualRect);
}
else
{
Expand Down
28 changes: 14 additions & 14 deletions Xamarin.Forms.Platform.WPF/Renderers/PageRenderer.cs
Original file line number Diff line number Diff line change
@@ -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<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);
}

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<VisualElement>().FirstOrDefault() ?? page.Content;
Control.Content = _currentView != null ? Platform.GetOrCreateRenderer(_currentView).GetNativeElement() : null;
}
}
}
}
}

0 comments on commit 4be8ddb

Please sign in to comment.