Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WPF] Fixes ControlTemplate sizing issue #2656

Merged
merged 2 commits into from Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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;
}
}
}
Expand Up @@ -240,6 +240,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Effects\AttachedStateEffect.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Effects\AttachedStateEffectList.cs" />
<Compile Include="$(MSBuildThisFileDirectory)GitHub1702.cs" />
<Compile Include="$(MSBuildThisFileDirectory)GitHub2642.cs" />
<Compile Include="$(MSBuildThisFileDirectory)GitHub2598.cs" />
<Compile Include="$(MSBuildThisFileDirectory)GitHub1878.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue1677.cs" />
Expand Down
18 changes: 16 additions & 2 deletions Xamarin.Forms.Platform.WPF/FormsContentLoader.cs
Expand Up @@ -54,11 +54,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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't you cast to IControlTemplated ? or are you 100% sure that this only needs to be done on ContentPages ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IControlTemplated does not define the Content property.
Only on ContentPage has Content property which we need.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about ContentView ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback.
I added check ContentView. Except i haven't tested it yet.

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