Issue4879 ImageButton Padding (UWP) (#5837)
* Apply ImageButton.Padding on UWP like other platforms For #4879 * Apply ImageButton.Padding on UWP like other platforms For #4879 * Apply ImageButton.Padding on UWP like other platforms For #4879 * don't use obsolete property after rebasing to 4.0 fixes #4879
This commit is contained in:
Родитель
442cb3e116
Коммит
7a0db78be9
|
@ -0,0 +1,86 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
|
||||
#if UITEST
|
||||
using NUnit.Framework;
|
||||
using Xamarin.UITest;
|
||||
using Xamarin.Forms.Core.UITests;
|
||||
#endif
|
||||
|
||||
namespace Xamarin.Forms.Controls.Issues
|
||||
{
|
||||
[Preserve(AllMembers = true)]
|
||||
[Issue(IssueTracker.Github, 4879, "4879 - ImageButtonPadding", PlatformAffected.UWP)]
|
||||
public class Issue4879 : TestContentPage
|
||||
{
|
||||
protected override async void Init()
|
||||
{
|
||||
await Navigation.PushModalAsync(new Issue4879Page());
|
||||
}
|
||||
|
||||
public class Issue4879Page : ContentPage
|
||||
{
|
||||
public Issue4879Page()
|
||||
{
|
||||
Button b = new Button
|
||||
{
|
||||
HorizontalOptions = LayoutOptions.End,
|
||||
VerticalOptions = LayoutOptions.End,
|
||||
ImageSource = "coffee.png",
|
||||
Padding = new Thickness(10),
|
||||
BackgroundColor = Color.Green
|
||||
};
|
||||
// Add BorderWidth to ImageButtons to match border of Button and allow for easier size comparisons
|
||||
ImageButton ib1 = new ImageButton
|
||||
{
|
||||
HorizontalOptions = LayoutOptions.Start,
|
||||
VerticalOptions = LayoutOptions.End,
|
||||
BorderWidth = 2,
|
||||
Source = "coffee.png",
|
||||
Padding = new Thickness(10),
|
||||
BackgroundColor = Color.Purple
|
||||
};
|
||||
ImageButton ib2 = new ImageButton
|
||||
{
|
||||
HorizontalOptions = LayoutOptions.End,
|
||||
VerticalOptions = LayoutOptions.Start,
|
||||
BorderWidth = 2,
|
||||
Source = "coffee.png",
|
||||
Padding = new Thickness(10),
|
||||
BackgroundColor = Color.Red
|
||||
};
|
||||
Grid mainG = new Grid
|
||||
{
|
||||
ColumnDefinitions = {
|
||||
new ColumnDefinition { Width = GridLength.Star },
|
||||
new ColumnDefinition { Width = GridLength.Star }
|
||||
},
|
||||
RowDefinitions = {
|
||||
new RowDefinition { Height = GridLength.Star },
|
||||
new RowDefinition { Height = GridLength.Star }
|
||||
}
|
||||
};
|
||||
|
||||
// Green Button top left
|
||||
// Purple ImageButton top right to compare height
|
||||
// Red ImageButton bottom left to compare width
|
||||
mainG.Children.Add(b, 0, 0);
|
||||
mainG.Children.Add(ib1, 1, 0);
|
||||
mainG.Children.Add(ib2, 0, 1);
|
||||
Content = mainG;
|
||||
}
|
||||
}
|
||||
|
||||
#if UITEST
|
||||
[Test]
|
||||
[Category(UITestCategories.ManualReview)]
|
||||
public void Issue4879Test()
|
||||
{
|
||||
RunningApp.Screenshot("I am at Issue 4879 - All buttons/images should be the same size.");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@
|
|||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Helpers\GarbageCollectionHelper.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue4879.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue5555.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla59172.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)FlagTestHelpers.cs" />
|
||||
|
|
|
@ -54,13 +54,16 @@ namespace Xamarin.Forms.Platform.UWP
|
|||
|
||||
_measured = true;
|
||||
|
||||
// we have to include the padding, otherwise the image is smaller than expected
|
||||
var padding = new Size(Element.Padding.HorizontalThickness, Element.Padding.VerticalThickness);
|
||||
// The size needs to be the entire size needed for the button (including padding, borders, etc.)
|
||||
// Not just the size of the image.
|
||||
var btn = Control;
|
||||
btn.Measure(new Windows.Foundation.Size(widthConstraint, heightConstraint));
|
||||
|
||||
return new SizeRequest(_image.Source.GetImageSourceSize() + padding);
|
||||
var size = new Size(Math.Ceiling(btn.DesiredSize.Width), Math.Ceiling(btn.DesiredSize.Height));
|
||||
|
||||
return new SizeRequest(size);
|
||||
}
|
||||
|
||||
|
||||
protected async override void OnElementChanged(ElementChangedEventArgs<ImageButton> e)
|
||||
{
|
||||
base.OnElementChanged(e);
|
||||
|
@ -205,7 +208,8 @@ namespace Xamarin.Forms.Platform.UWP
|
|||
{
|
||||
_image.Margin = new WThickness(0);
|
||||
|
||||
Control.Padding = new WThickness(
|
||||
// Apply the padding to the containing button, not the image
|
||||
_formsButton.Padding = new WThickness(
|
||||
Element.Padding.Left,
|
||||
Element.Padding.Top,
|
||||
Element.Padding.Right,
|
||||
|
|
Загрузка…
Ссылка в новой задаче