summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.ControlGallery.WindowsUniversal
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-09-08 18:39:05 (GMT)
committerJason Smith <jason.smith@xamarin.com>2016-09-08 18:39:05 (GMT)
commit85426c5d9495eb1d55b3128bf97e50c68a73b53f (patch)
tree2f81e5868ce61eb90d15c6c51a354603b8395627 /Xamarin.Forms.ControlGallery.WindowsUniversal
parent11326e1c182b3ff5c3d82c6ef7d09c193bc19891 (diff)
downloadxamarin-forms-85426c5d9495eb1d55b3128bf97e50c68a73b53f.zip
xamarin-forms-85426c5d9495eb1d55b3128bf97e50c68a73b53f.tar.gz
xamarin-forms-85426c5d9495eb1d55b3128bf97e50c68a73b53f.tar.bz2
Native Bindings (#278)
* [C, I, A, W] Support Native Bindings * fix tabs
Diffstat (limited to 'Xamarin.Forms.ControlGallery.WindowsUniversal')
-rw-r--r--Xamarin.Forms.ControlGallery.WindowsUniversal/MainPage.xaml.cs75
1 files changed, 74 insertions, 1 deletions
diff --git a/Xamarin.Forms.ControlGallery.WindowsUniversal/MainPage.xaml.cs b/Xamarin.Forms.ControlGallery.WindowsUniversal/MainPage.xaml.cs
index 7e16e83..84767a5 100644
--- a/Xamarin.Forms.ControlGallery.WindowsUniversal/MainPage.xaml.cs
+++ b/Xamarin.Forms.ControlGallery.WindowsUniversal/MainPage.xaml.cs
@@ -1,6 +1,7 @@
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
using System;
+using System.Globalization;
using Windows.Foundation;
using Windows.Graphics.Display;
using Windows.UI.ViewManagement;
@@ -33,6 +34,12 @@ namespace Xamarin.Forms.ControlGallery.WindowsUniversal
if (nncgPage != null) {
AddNativeControls (nncgPage);
}
+
+ var nncgPage1 = args.Page as NativeBindingGalleryPage;
+
+ if (nncgPage1 != null) {
+ AddNativeBindings(nncgPage1);
+ }
};
}
@@ -105,5 +112,71 @@ namespace Xamarin.Forms.ControlGallery.WindowsUniversal
page.NativeControlsAdded = true;
}
- }
+
+ void AddNativeBindings(NativeBindingGalleryPage page)
+ {
+ if (page.NativeControlsAdded)
+ return;
+
+ StackLayout sl = page.Layout;
+
+ var txbLabel = new TextBlock {
+ FontSize = 14,
+ FontFamily = new FontFamily("HelveticaNeue")
+ };
+
+ var txbBox = new TextBox {
+ FontSize = 14,
+ FontFamily = new FontFamily("HelveticaNeue")
+ };
+
+ var btnColor = new Windows.UI.Xaml.Controls.Button { Content = "Toggle Label Color", Height = 80 };
+ btnColor.Click += (sender, args) => txbLabel.Foreground = new SolidColorBrush(Windows.UI.Colors.Pink);
+
+ var btnTextBox = new Windows.UI.Xaml.Controls.Button { Content = "Change text textbox", Height = 80 };
+ btnTextBox.Click += (sender, args) => txbBox.Text = "Hello 2 way native";
+
+ txbLabel.SetBinding("Text", new Binding("NativeLabel"));
+ txbBox.SetBinding("Text", new Binding("NativeLabel", BindingMode.TwoWay), "TextChanged");
+ txbLabel.SetBinding("Foreground", new Binding("NativeLabelColor", BindingMode.TwoWay, new ColorToBrushNativeBindingConverter()));
+
+ var grd = new StackPanel();
+ grd.Children.Add(txbLabel);
+ grd.Children.Add(btnColor);
+
+ sl?.Children.Add(grd.ToView());
+
+ sl?.Children.Add(txbBox);
+ sl?.Children.Add(btnTextBox.ToView());
+
+ page.NativeControlsAdded = true;
+ }
+
+ class ColorToBrushNativeBindingConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (value is Color)
+ return new SolidColorBrush(ToWindowsColor((Color)value));
+
+ return null;
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (value is SolidColorBrush)
+ return ToColor(((SolidColorBrush)value).Color);
+
+ return null;
+ }
+ public static Windows.UI.Color ToWindowsColor(Color color)
+ {
+ return Windows.UI.Color.FromArgb((byte)(color.A * 255), (byte)(color.R * 255), (byte)(color.G * 255), (byte)(color.B * 255));
+ }
+ public static Color ToColor(Windows.UI.Color color)
+ {
+ return Color.FromRgba(color.R, color.G, color.B, color.A);
+ }
+ }
+ }
}