summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT')
-rw-r--r--Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs79
-rw-r--r--Xamarin.Forms.Platform.WinRT/WindowsBasePlatformServices.cs2
2 files changed, 67 insertions, 14 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs b/Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs
index 131e5f9..04c39ca 100644
--- a/Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs
+++ b/Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs
@@ -125,25 +125,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()
diff --git a/Xamarin.Forms.Platform.WinRT/WindowsBasePlatformServices.cs b/Xamarin.Forms.Platform.WinRT/WindowsBasePlatformServices.cs
index dcda2c2..614a097 100644
--- a/Xamarin.Forms.Platform.WinRT/WindowsBasePlatformServices.cs
+++ b/Xamarin.Forms.Platform.WinRT/WindowsBasePlatformServices.cs
@@ -118,7 +118,7 @@ namespace Xamarin.Forms.Platform.WinRT
using (var client = new HttpClient())
{
HttpResponseMessage streamResponse = await client.GetAsync(uri.AbsoluteUri).ConfigureAwait(false);
- return await streamResponse.Content.ReadAsStreamAsync().ConfigureAwait(false);
+ return streamResponse.IsSuccessStatusCode ? await streamResponse.Content.ReadAsStreamAsync().ConfigureAwait(false) : null;
}
}