summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT
diff options
context:
space:
mode:
authorSamantha Houts <samantha@teamredwall.com>2016-03-31 17:43:59 (GMT)
committerSamantha Houts <samantha@teamredwall.com>2016-03-31 17:43:59 (GMT)
commitd22a5c7c32701aa6b830b09e52d8e272a9d0a97f (patch)
treedf0b2e44d1d71fbc32b55cd16ead8ccb69d36e30 /Xamarin.Forms.Platform.WinRT
parent850591679f51ed27cf00707296156ab4ed363873 (diff)
parent17e2a4b94d5105b53c5875d9416d043f14313305 (diff)
downloadxamarin-forms-d22a5c7c32701aa6b830b09e52d8e272a9d0a97f.zip
xamarin-forms-d22a5c7c32701aa6b830b09e52d8e272a9d0a97f.tar.gz
xamarin-forms-d22a5c7c32701aa6b830b09e52d8e272a9d0a97f.tar.bz2
Merge pull request #11 from xamarin/fix-bugzilla27417
Add options for specifying layout of button text/image content
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT')
-rw-r--r--Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs79
1 files changed, 66 insertions, 13 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs b/Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs
index 60ee641..bcba31c 100644
--- a/Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs
+++ b/Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs
@@ -117,25 +117,78 @@ namespace Xamarin.Forms.Platform.WinRT
void UpdateContent()
{
- if (Element.Image != null)
+ var text = Element.Text;
+ var elementImage = Element.Image;
+
+ // No image, just the text
+ if (elementImage == null)
{
- var panel = new StackPanel { Orientation = Orientation.Horizontal };
+ Control.Content = text;
+ return;
+ }
- var image = new WImage { Source = new BitmapImage(new Uri("ms-appx:///" + Element.Image.File)), Width = 30, Height = 30, Margin = new WThickness(0, 0, 20, 0) };
- panel.Children.Add(image);
- image.ImageOpened += (sender, args) => { ((IButtonController)Element).NativeSizeChanged(); };
+ var image = new WImage
+ {
+ Source = new BitmapImage(new Uri("ms-appx:///" + elementImage.File)),
+ Width = 30,
+ Height = 30,
+ VerticalAlignment = VerticalAlignment.Center,
+ HorizontalAlignment = HorizontalAlignment.Center
+ };
+
+ // No text, just the image
+ if (string.IsNullOrEmpty(text))
+ {
+ Control.Content = image;
+ return;
+ }
- if (Element.Text != null)
- {
- panel.Children.Add(new TextBlock { Text = Element.Text });
- }
+ // Both image and text, so we need to build a container for them
+ var layout = Element.ContentLayout;
+ var container = new StackPanel();
+ var textBlock = new TextBlock
+ {
+ Text = text,
+ VerticalAlignment = VerticalAlignment.Center,
+ HorizontalAlignment = HorizontalAlignment.Center
+ };
- Control.Content = panel;
- }
- else
+ var spacing = layout.Spacing;
+
+ container.HorizontalAlignment = HorizontalAlignment.Center;
+ container.VerticalAlignment = VerticalAlignment.Center;
+
+ switch (layout.Position)
{
- Control.Content = Element.Text;
+ 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;
}
+
+ Control.Content = container;
+
}
void UpdateFont()