summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT
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.WinRT
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.WinRT')
-rw-r--r--Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs28
1 files changed, 19 insertions, 9 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs b/Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs
index 04c39caf..018fdd4d 100644
--- a/Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs
+++ b/Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs
@@ -4,6 +4,7 @@ using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
+using Xamarin.Forms.Internals;
using WThickness = Windows.UI.Xaml.Thickness;
using WButton = Windows.UI.Xaml.Controls.Button;
using WImage = Windows.UI.Xaml.Controls.Image;
@@ -135,13 +136,20 @@ namespace Xamarin.Forms.Platform.WinRT
return;
}
+ var bmp = new BitmapImage(new Uri("ms-appx:///" + elementImage.File));
+
var image = new WImage
{
- Source = new BitmapImage(new Uri("ms-appx:///" + elementImage.File)),
- Width = 30,
- Height = 30,
+ Source = bmp,
VerticalAlignment = VerticalAlignment.Center,
- HorizontalAlignment = HorizontalAlignment.Center
+ HorizontalAlignment = HorizontalAlignment.Center,
+ Stretch = Stretch.Uniform
+ };
+
+ bmp.ImageOpened += (sender, args) => {
+ image.Width = bmp.PixelWidth;
+ image.Height = bmp.PixelHeight;
+ Element.InvalidateMeasureInternal(InvalidationTrigger.RendererReady);
};
// No text, just the image
@@ -152,10 +160,13 @@ namespace Xamarin.Forms.Platform.WinRT
}
// 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
@@ -195,8 +206,7 @@ namespace Xamarin.Forms.Platform.WinRT
break;
}
- Control.Content = container;
-
+ return container;
}
void UpdateFont()