diff options
author | Rui Marinho <me@ruimarinho.net> | 2016-09-30 19:48:22 +0100 |
---|---|---|
committer | Rui Marinho <me@ruimarinho.net> | 2016-10-04 17:32:34 +0100 |
commit | 00a42778203539a0adf6037ba3f4dcad70c1869a (patch) | |
tree | 6771f05937b71c60e4902913e486ecb65e6fc452 /Xamarin.Forms.ControlGallery.iOS | |
parent | 65e06eef9051d5930d368f87c87d70044fc27f79 (diff) | |
download | xamarin-forms-00a42778203539a0adf6037ba3f4dcad70c1869a.tar.gz xamarin-forms-00a42778203539a0adf6037ba3f4dcad70c1869a.tar.bz2 xamarin-forms-00a42778203539a0adf6037ba3f4dcad70c1869a.zip |
[iOS] Keep our native property listener around the same time we keep our proxy, check if we are KVO compliant before adding observer (#403)
Diffstat (limited to 'Xamarin.Forms.ControlGallery.iOS')
-rw-r--r-- | Xamarin.Forms.ControlGallery.iOS/AppDelegate.cs | 34 | ||||
-rw-r--r-- | Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj | 2 |
2 files changed, 35 insertions, 1 deletions
diff --git a/Xamarin.Forms.ControlGallery.iOS/AppDelegate.cs b/Xamarin.Forms.ControlGallery.iOS/AppDelegate.cs index 7614796a..5e1dcd79 100644 --- a/Xamarin.Forms.ControlGallery.iOS/AppDelegate.cs +++ b/Xamarin.Forms.ControlGallery.iOS/AppDelegate.cs @@ -312,6 +312,12 @@ namespace Xamarin.Forms.ControlGallery.iOS uilabel.SetBinding("Text", new Binding("NativeLabel")); uilabel.SetBinding(nameof(uilabel.TextColor), new Binding("NativeLabelColor", converter: nativeColorConverter)); + var kvoSlider = new KVOUISlider(); + kvoSlider.MaxValue = 100; + kvoSlider.MinValue = 0; + kvoSlider.SetBinding(nameof(kvoSlider.KVOValue), new Binding("Age", BindingMode.TwoWay)); + sl?.Children.Add(kvoSlider); + var uiView = new UIView(new RectangleF(0, 0, width, heightCustomLabelView)); uiView.Add(uilabel); sl?.Children.Add(uiView); @@ -323,6 +329,34 @@ namespace Xamarin.Forms.ControlGallery.iOS } } + [Register("KVOUISlider")] + public class KVOUISlider : UISlider + { + + public KVOUISlider() + { + ValueChanged += (s, e) => KVOValue = Value; + } + + float _kVOValue; + [Export("kvovalue")] + public float KVOValue + { + get + { + + return _kVOValue; + } + set + { + + WillChangeValue(nameof(KVOValue).ToLower()); + _kVOValue = Value = value; + DidChangeValue(nameof(KVOValue).ToLower()); + } + } + } + public class ColorConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj b/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj index fabf981a..aa9c7d91 100644 --- a/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj +++ b/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj @@ -270,4 +270,4 @@ <Visible>False</Visible> </XamarinComponentReference> </ItemGroup> -</Project>
\ No newline at end of file +</Project> |