Skip to content

Commit

Permalink
[WPF] Fixes ControlTemplate sizing issue (xamarin#2656)
Browse files Browse the repository at this point in the history
- fixes xamarin#2642
  • Loading branch information
Pavel Yakovlev authored and StephaneDelcroix committed Oct 19, 2018
1 parent 238cf94 commit ded3d0f
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 2642, "ControlTemplate resizing issue", PlatformAffected.WPF)]
public class GitHub2642 : TestContentPage
{
public class PresenterWrapper : ContentView
{
public PresenterWrapper()
{
Content = new ContentPresenter();
}
}

protected override void Init()
{
this.ControlTemplate = new ControlTemplate(typeof(PresenterWrapper));

var grid = new Grid()
{
RowDefinitions = new RowDefinitionCollection
{
new RowDefinition { Height = new GridLength(0, GridUnitType.Auto) },
new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
}
};

grid.AddChild(new Label()
{
Text = "Header",
LineBreakMode = LineBreakMode.WordWrap,
FontSize = 24

}, 0, 0);

grid.AddChild(new Label()
{
Text = "Lorem ipsum dolor sit amet, sed at etiam graecis. Amet dicta utroque in ius, error vituperatoribus vel ex. " +
"Cu duo veri aperiam honestatis. Quo sint movet ullamcorper cu, vero vidisse argumentum ne nec, in munere eirmod eum. " +
"Persius similique reformidans ex mei, cu quo quot nihil mediocrem.",
LineBreakMode = LineBreakMode.WordWrap

}, 0, 1);

Content = grid;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Effects\AttachedStateEffectList.cs" />
<Compile Include="$(MSBuildThisFileDirectory)GitHub1648.cs" />
<Compile Include="$(MSBuildThisFileDirectory)GitHub1702.cs" />
<Compile Include="$(MSBuildThisFileDirectory)GitHub2642.cs" />
<Compile Include="$(MSBuildThisFileDirectory)GitHub1700.cs" />
<Compile Include="$(MSBuildThisFileDirectory)GitHub2598.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue1483.cs" />
Expand Down
18 changes: 16 additions & 2 deletions Xamarin.Forms.Platform.WPF/FormsContentLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,25 @@ private object CreateOrResizeContent(FrameworkElement parent, VisualElement visu
//if (Debugger.IsAttached)
// Console.WriteLine("Page type : " + visualElement.GetType() + " (" + (visualElement as Page).Title + ") -- Parent type : " + visualElement.Parent.GetType() + " -- " + parent.ActualHeight + "H*" + parent.ActualWidth + "W");

visualElement.Layout(new Rectangle(0, 0, parent.ActualWidth, parent.ActualHeight));
var actualRect = new Rectangle(0, 0, parent.ActualWidth, parent.ActualHeight);
visualElement.Layout(actualRect);

// ControlTemplate adds an additional layer through which to send sizing changes.
var contentPage = visualElement as ContentPage;
if (contentPage?.ControlTemplate != null)
{
contentPage.Content?.Layout(actualRect);
}
else
{
var contentView = visualElement as ContentView;
if (contentView?.ControlTemplate != null)
contentView.Content?.Layout(actualRect);
}

IPageController pageController = visualElement.RealParent as IPageController;
if (pageController != null)
pageController.ContainerArea = new Rectangle(0, 0, parent.ActualWidth, parent.ActualHeight);
pageController.ContainerArea = actualRect;

return renderer.GetNativeElement();
}
Expand Down

0 comments on commit ded3d0f

Please sign in to comment.