summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WP8/NavigationMenuRenderer.cs
diff options
context:
space:
mode:
authorJason Smith <jason.smith@xamarin.com>2016-03-22 20:02:25 (GMT)
committerJason Smith <jason.smith@xamarin.com>2016-03-22 23:13:41 (GMT)
commit17fdde66d94155fc62a034fa6658995bef6fd6e5 (patch)
treeb5e5073a2a7b15cdbe826faa5c763e270a505729 /Xamarin.Forms.Platform.WP8/NavigationMenuRenderer.cs
downloadxamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.zip
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.gz
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.bz2
Initial import
Diffstat (limited to 'Xamarin.Forms.Platform.WP8/NavigationMenuRenderer.cs')
-rw-r--r--Xamarin.Forms.Platform.WP8/NavigationMenuRenderer.cs85
1 files changed, 85 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.WP8/NavigationMenuRenderer.cs b/Xamarin.Forms.Platform.WP8/NavigationMenuRenderer.cs
new file mode 100644
index 0000000..c5a983d
--- /dev/null
+++ b/Xamarin.Forms.Platform.WP8/NavigationMenuRenderer.cs
@@ -0,0 +1,85 @@
+´╗┐using System;
+using System.ComponentModel;
+using System.Windows.Media.Imaging;
+using Microsoft.Phone.Controls;
+
+namespace Xamarin.Forms.Platform.WinPhone
+{
+ internal class NavigationMenuRenderer : ViewRenderer<NavigationMenu, System.Windows.Controls.Grid>
+ {
+ const int Spacing = 12;
+
+ protected override void OnElementChanged(ElementChangedEventArgs<NavigationMenu> e)
+ {
+ base.OnElementChanged(e);
+
+ var grid = new System.Windows.Controls.Grid();
+ grid.ColumnDefinitions.Add(new System.Windows.Controls.ColumnDefinition { Width = System.Windows.GridLength.Auto });
+ grid.ColumnDefinitions.Add(new System.Windows.Controls.ColumnDefinition { Width = System.Windows.GridLength.Auto });
+
+ UpdateItems(grid);
+ SetNativeControl(grid);
+ }
+
+ protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
+ {
+ base.OnElementPropertyChanged(sender, e);
+
+ switch (e.PropertyName)
+ {
+ case "Targets":
+ UpdateItems(Control);
+ break;
+ }
+ }
+
+ TileSize GetSize()
+ {
+ return RenderSize.Width >= 210 * 2 + Spacing ? TileSize.Medium : TileSize.Default;
+ }
+
+ void UpdateItems(System.Windows.Controls.Grid grid)
+ {
+ grid.Children.Clear();
+
+ grid.RowDefinitions.Clear();
+
+ var x = 0;
+ var y = 0;
+ foreach (Page target in Element.Targets)
+ {
+ if (x > 1)
+ {
+ x = 0;
+ y++;
+ }
+
+ if (x == 0)
+ grid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition());
+
+ var hubTile = new HubTile { Title = target.Title, Source = new BitmapImage(new Uri(target.Icon, UriKind.Relative)), Margin = new System.Windows.Thickness(0, 0, Spacing, Spacing) };
+
+ if (target.BackgroundColor != Color.Default)
+ hubTile.Background = target.BackgroundColor.ToBrush();
+
+ Page tmp = target;
+ hubTile.Tap += (sender, args) => Element.SendTargetSelected(tmp);
+
+ hubTile.SetValue(System.Windows.Controls.Grid.RowProperty, y);
+ hubTile.SetValue(System.Windows.Controls.Grid.ColumnProperty, x);
+ hubTile.Size = GetSize();
+
+ var weakRef = new WeakReference(hubTile);
+ SizeChanged += (sender, args) =>
+ {
+ if (weakRef.IsAlive)
+ ((HubTile)weakRef.Target).Size = GetSize();
+ ((IVisualElementController)Element).NativeSizeChanged();
+ };
+
+ x++;
+ grid.Children.Add(hubTile);
+ }
+ }
+ }
+} \ No newline at end of file