summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WP8
diff options
context:
space:
mode:
authorE.Z. Hart <hartez@users.noreply.github.com>2016-06-08 09:47:00 -0600
committerRui Marinho <me@ruimarinho.net>2016-06-08 16:47:00 +0100
commit4146d617a038e3dd748d6f42796dd791f28145b0 (patch)
tree72ed572473fd691934ba4a60b64d4085057775fe /Xamarin.Forms.Platform.WP8
parentd1b8ac5c940c6f2ae6798337be53ececd60992f7 (diff)
downloadxamarin-forms-4146d617a038e3dd748d6f42796dd791f28145b0.tar.gz
xamarin-forms-4146d617a038e3dd748d6f42796dd791f28145b0.tar.bz2
xamarin-forms-4146d617a038e3dd748d6f42796dd791f28145b0.zip
Remove hard-coded image sizes for button images (#202)
Diffstat (limited to 'Xamarin.Forms.Platform.WP8')
-rw-r--r--Xamarin.Forms.Platform.WP8/ButtonRenderer.cs35
1 files changed, 25 insertions, 10 deletions
diff --git a/Xamarin.Forms.Platform.WP8/ButtonRenderer.cs b/Xamarin.Forms.Platform.WP8/ButtonRenderer.cs
index a75173b6..575de4f3 100644
--- a/Xamarin.Forms.Platform.WP8/ButtonRenderer.cs
+++ b/Xamarin.Forms.Platform.WP8/ButtonRenderer.cs
@@ -4,6 +4,7 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
+using Xamarin.Forms.Internals;
using WButton = System.Windows.Controls.Button;
using WImage = System.Windows.Controls.Image;
using WThickness = System.Windows.Thickness;
@@ -91,15 +92,21 @@ namespace Xamarin.Forms.Platform.WinPhone
return;
}
+ var bmp = new BitmapImage(new Uri("/" + elementImage.File, UriKind.Relative));
+
var image = new WImage
{
- Source = new BitmapImage(new Uri("/" + elementImage.File, UriKind.Relative)),
- Width = 30,
- Height = 30,
+ Source = bmp,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Center
};
+ bmp.ImageOpened += (sender, args) => {
+ image.Width = bmp.PixelWidth;
+ image.Height = bmp.PixelHeight;
+ Element.InvalidateMeasureInternal(InvalidationTrigger.RendererReady);
+ };
+
// No text, just the image
if (string.IsNullOrEmpty(text))
{
@@ -108,10 +115,13 @@ namespace Xamarin.Forms.Platform.WinPhone
}
// Both image and text, so we need to build a container for them
- var layout = Element.ContentLayout;
+ Control.Content = CreateContentContainer(Element.ContentLayout, image, text);
+ }
+
+ static StackPanel CreateContentContainer(Button.ButtonContentLayout layout, WImage image, string text)
+ {
var container = new StackPanel();
- var textBlock = new TextBlock
- {
+ var textBlock = new TextBlock {
Text = text,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Center
@@ -127,26 +137,31 @@ namespace Xamarin.Forms.Platform.WinPhone
case Button.ButtonContentLayout.ImagePosition.Top:
container.Orientation = Orientation.Vertical;
image.Margin = new WThickness(0, 0, 0, spacing);
+ container.Children.Add(image);
+ container.Children.Add(textBlock);
break;
case Button.ButtonContentLayout.ImagePosition.Bottom:
container.Orientation = Orientation.Vertical;
image.Margin = new WThickness(0, spacing, 0, 0);
+ container.Children.Add(textBlock);
+ container.Children.Add(image);
break;
case Button.ButtonContentLayout.ImagePosition.Right:
container.Orientation = Orientation.Horizontal;
image.Margin = new WThickness(spacing, 0, 0, 0);
+ container.Children.Add(textBlock);
+ container.Children.Add(image);
break;
default:
// Defaults to image on the left
container.Orientation = Orientation.Horizontal;
image.Margin = new WThickness(0, 0, spacing, 0);
+ container.Children.Add(image);
+ container.Children.Add(textBlock);
break;
}
- container.Children.Add(image);
- container.Children.Add(textBlock);
-
- Control.Content = container;
+ return container;
}
void UpdateFont()