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: PixelLayout now respects the desired and contained size #1988

Merged
merged 1 commit into from
Jul 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/Eto.Wpf/Forms/PixelLayoutHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ public class PixelLayoutHandler : WpfLayout<swc.Canvas, PixelLayout, PixelLayout
{
public class EtoCanvas : swc.Canvas
{
public IWpfFrameworkElement Handler { get; set; }

protected override sw.Size MeasureOverride(sw.Size constraint)
{
return Handler?.MeasureOverride(constraint, MeasureChildren) ?? MeasureChildren(constraint);
}

sw.Size MeasureChildren(sw.Size constraint)
{
var size = new sw.Size();

Expand All @@ -23,15 +30,16 @@ protected override sw.Size MeasureOverride(sw.Size constraint)
if (size.Width < left) size.Width = left;
if (size.Height < top) size.Height = top;
}
return size;
return size.Min(constraint.InfinityIfNan());
}
}

public PixelLayoutHandler()
{
Control = new EtoCanvas
{
SnapsToDevicePixels = true
Handler = this,
SnapsToDevicePixels = true,
};
}

Expand Down