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.Controls/ControlGalleryPages | |
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.Controls/ControlGalleryPages')
-rw-r--r-- | Xamarin.Forms.Controls/ControlGalleryPages/NativeBindingGalleryPage.cs | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/Xamarin.Forms.Controls/ControlGalleryPages/NativeBindingGalleryPage.cs b/Xamarin.Forms.Controls/ControlGalleryPages/NativeBindingGalleryPage.cs new file mode 100644 index 00000000..51d9b970 --- /dev/null +++ b/Xamarin.Forms.Controls/ControlGalleryPages/NativeBindingGalleryPage.cs @@ -0,0 +1,101 @@ +using System; +using Xamarin.Forms.Internals; + +namespace Xamarin.Forms.Controls +{ + public class NativeBindingGalleryPage : ContentPage + { + public StackLayout Layout { get; set; } + public bool NativeControlsAdded { get; set; } + + NestedNativeViewModel ViewModel { get; set; } + + public NativeBindingGalleryPage() + { + + var vm = new NestedNativeViewModel(); + vm.FormsLabel = "Forms Label Binding"; + vm.NativeLabel = "Native Label Binding"; + vm.NativeLabelColor = Color.Red; + vm.Age = 45; + + Layout = new StackLayout { Padding = 20, VerticalOptions = LayoutOptions.FillAndExpand }; + + var buttonNav = new Button { Text = "New Page" }; + buttonNav.Clicked += (object sender, EventArgs e) => + { + App.Current.MainPage = new ContentPage { Content = new Label { Text = "New page" } }; + }; + + var button = new Button { Text = "Change BindingContext " }; + button.Clicked += (object sender, EventArgs e) => + { + vm = new NestedNativeViewModel(); + vm.FormsLabel = "Forms Label Binding Changed"; + vm.NativeLabel = "Native Label Binding Changed"; + vm.NativeLabelColor = Color.Pink; + vm.Age = 10; + + BindingContext = ViewModel = vm; ; + }; + + var boxView = new BoxView { HeightRequest = 50 }; + boxView.SetBinding(BoxView.BackgroundColorProperty, "NativeLabelColor"); + + var label = new Label(); + label.SetBinding(Label.TextProperty, "FormsLabel"); + + Layout.Children.Add(buttonNav); + + Layout.Children.Add(label); + + Layout.Children.Add(boxView); + Layout.Children.Add(button); + + BindingContext = ViewModel = vm; ; + + Content = new ScrollView { Content = Layout }; + } + } + + + [Preserve(AllMembers = true)] + public class NestedNativeViewModel : ViewModelBase + { + string _formsLabel; + public string FormsLabel + { + get { return _formsLabel; } + set { _formsLabel = value; OnPropertyChanged(); } + } + + string _nativeLabel; + public string NativeLabel + { + get { return _nativeLabel; } + set { _nativeLabel = value; OnPropertyChanged(); } + } + + Color _nativeLabelColor; + public Color NativeLabelColor + { + get { return _nativeLabelColor; } + set { _nativeLabelColor = value; OnPropertyChanged(); } + } + + int _age; + public int Age + { + get { return _age; } + set { _age = value; OnPropertyChanged(); } + } + + bool _selected; + public bool Selected + { + get { return _selected; } + set { _selected = value; OnPropertyChanged(); } + } + } + +} |