diff options
author | Stephane Delcroix <stephane@delcroix.org> | 2016-09-08 20:39:05 +0200 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-09-08 11:39:05 -0700 |
commit | 85426c5d9495eb1d55b3128bf97e50c68a73b53f (patch) | |
tree | 2f81e5868ce61eb90d15c6c51a354603b8395627 /Xamarin.Forms.ControlGallery.iOS | |
parent | 11326e1c182b3ff5c3d82c6ef7d09c193bc19891 (diff) | |
download | xamarin-forms-85426c5d9495eb1d55b3128bf97e50c68a73b53f.tar.gz xamarin-forms-85426c5d9495eb1d55b3128bf97e50c68a73b53f.tar.bz2 xamarin-forms-85426c5d9495eb1d55b3128bf97e50c68a73b53f.zip |
Native Bindings (#278)
* [C, I, A, W] Support Native Bindings
* fix tabs
Diffstat (limited to 'Xamarin.Forms.ControlGallery.iOS')
-rw-r--r-- | Xamarin.Forms.ControlGallery.iOS/AppDelegate.cs | 68 | ||||
-rw-r--r-- | Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj | 9 |
2 files changed, 77 insertions, 0 deletions
diff --git a/Xamarin.Forms.ControlGallery.iOS/AppDelegate.cs b/Xamarin.Forms.ControlGallery.iOS/AppDelegate.cs index 8f064d34..c4d8eaf0 100644 --- a/Xamarin.Forms.ControlGallery.iOS/AppDelegate.cs +++ b/Xamarin.Forms.ControlGallery.iOS/AppDelegate.cs @@ -8,15 +8,18 @@ using System.IO; using UIKit; using Foundation; using CoreGraphics; +using AdvancedColorPicker; #else using MonoTouch.UIKit; using MonoTouch.Foundation; +using MonoTouch.CoreGraphics; #endif using Xamarin.Forms; using Xamarin.Forms.ControlGallery.iOS; using Xamarin.Forms.Controls; using Xamarin.Forms.Maps.iOS; using Xamarin.Forms.Platform.iOS; +using System.Globalization; [assembly: Dependency (typeof (TestCloudService))] [assembly: Dependency (typeof (StringProvider))] @@ -163,6 +166,13 @@ namespace Xamarin.Forms.ControlGallery.iOS if (nncgPage != null) { AddNativeControls (nncgPage); } + + var nncgPage1 = args.Page as NativeBindingGalleryPage; + + if (nncgPage1 != null) + { + AddNativeBindings(nncgPage1); + } }; } @@ -271,6 +281,64 @@ namespace Xamarin.Forms.ControlGallery.iOS // And we'll use the width (which is fine) and substitute our own height return new SizeRequest (new Size (badRect.Width, 20)); } + + void AddNativeBindings(NativeBindingGalleryPage page) + { + if (page.NativeControlsAdded) + return; + + StackLayout sl = page.Layout; + + int width = (int)sl.Width; + int heightCustomLabelView = 100; + + var uilabel = new UILabel(new RectangleF(0, 0, width, heightCustomLabelView)) + { + MinimumFontSize = 14f, + Lines = 0, + LineBreakMode = UILineBreakMode.WordWrap, + Font = UIFont.FromName("Helvetica", 24f), + Text = "DefaultText" + }; + + var uibuttonColor = new UIButton(UIButtonType.RoundedRect); + uibuttonColor.SetTitle("Toggle Text Color Binding", UIControlState.Normal); + uibuttonColor.Font = UIFont.FromName("Helvetica", 14f); + uibuttonColor.TouchUpInside += (sender, args) => uilabel.TextColor = UIColor.Blue; + + var nativeColorConverter = new ColorConverter(); + + uilabel.SetBinding("Text", new Binding("NativeLabel")); + uilabel.SetBinding(nameof(uilabel.TextColor), new Binding("NativeLabelColor", converter: nativeColorConverter)); + + var uiView = new UIView(new RectangleF(0, 0, width, heightCustomLabelView)); + uiView.Add(uilabel); + sl?.Children.Add(uiView); + sl?.Children.Add(uibuttonColor.ToView()); +#if !_CLASSIC_ + var colorPicker = new ColorPickerView(new CGRect(0, 0, width, 300)); + colorPicker.SetBinding("SelectedColor", new Binding("NativeLabelColor", BindingMode.TwoWay, nativeColorConverter), "ColorPicked"); + sl?.Children.Add(colorPicker); +#endif + page.NativeControlsAdded = true; + } + } + + public class ColorConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is Color) + return ((Color)value).ToUIColor(); + return value; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is UIColor) + return ((UIColor)value).ToColor(); + return value; + } } #endif } diff --git a/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj b/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj index d3dc36b2..35951c56 100644 --- a/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj +++ b/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj @@ -250,6 +250,9 @@ <Reference Include="Calabash"> <HintPath>..\packages\Xamarin.TestCloud.Agent.0.19.1\lib\Xamarin.iOS10\Calabash.dll</HintPath> </Reference> + <Reference Include="AdvancedColorPicker"> + <HintPath>..\Components\advancedcolorpicker-2.0\lib\ios-unified\AdvancedColorPicker.dll</HintPath> + </Reference> </ItemGroup> <Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" /> <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> @@ -261,4 +264,10 @@ <Error Condition="!Exists('..\packages\Xamarin.Insights.1.11.4\build\Xamarin.iOS10\Xamarin.Insights.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Xamarin.Insights.1.11.4\build\Xamarin.iOS10\Xamarin.Insights.targets'))" /> </Target> <ItemGroup /> + <ItemGroup> + <XamarinComponentReference Include="advancedcolorpicker"> + <Version>2.0</Version> + <Visible>False</Visible> + </XamarinComponentReference> + </ItemGroup> </Project>
\ No newline at end of file |