summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls/GalleryPages/BoundContentPage.cs
diff options
context:
space:
mode:
authorJason Smith <jason.smith@xamarin.com>2016-03-22 13:02:25 -0700
committerJason Smith <jason.smith@xamarin.com>2016-03-22 16:13:41 -0700
commit17fdde66d94155fc62a034fa6658995bef6fd6e5 (patch)
treeb5e5073a2a7b15cdbe826faa5c763e270a505729 /Xamarin.Forms.Controls/GalleryPages/BoundContentPage.cs
downloadxamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.gz
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.bz2
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.zip
Initial import
Diffstat (limited to 'Xamarin.Forms.Controls/GalleryPages/BoundContentPage.cs')
-rw-r--r--Xamarin.Forms.Controls/GalleryPages/BoundContentPage.cs79
1 files changed, 79 insertions, 0 deletions
diff --git a/Xamarin.Forms.Controls/GalleryPages/BoundContentPage.cs b/Xamarin.Forms.Controls/GalleryPages/BoundContentPage.cs
new file mode 100644
index 00000000..e3051fde
--- /dev/null
+++ b/Xamarin.Forms.Controls/GalleryPages/BoundContentPage.cs
@@ -0,0 +1,79 @@
+using System;
+using System.Globalization;
+using System.Windows.Input;
+
+namespace Xamarin.Forms.Controls
+{
+ [Preserve (AllMembers = true)]
+ public class BoundContentPage : ContentPage
+ {
+ internal class NavWrapperConverter : IValueConverter
+ {
+ public object Convert (object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ throw new NotSupportedException ();
+ }
+
+ public object ConvertBack (object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ return new NavigationWrapper ((INavigation) value);
+ }
+ }
+
+ internal class NavigationWrapper
+ {
+ // This class is dumb but proves you can wrap the INavigation with a converter to do some MVVM goodness
+ // Normally this class would implement pushes with ViewModel then do the conversion
+ readonly INavigation _inner;
+
+ public NavigationWrapper (INavigation inner )
+ {
+ _inner = inner;
+ }
+
+ public void WrappedPush ()
+ {
+ _inner.PushAsync (new ContentPage {
+ Content = new StackLayout {
+ BackgroundColor = Color.Red,
+ Children = {
+ new Label {
+ Text = "Second Page"
+ }
+ }
+ }
+ });
+ }
+ }
+
+ [Preserve (AllMembers = true)]
+ internal class BoundContentPageViewModel
+ {
+ public string ButtonText { get { return "Click Me!"; } }
+
+ public ICommand ButtonCommand { get; set; }
+
+ public NavigationWrapper Navigation { get; set; }
+
+ public BoundContentPageViewModel ()
+ {
+ ButtonCommand = new Command (() => Navigation.WrappedPush ());
+ }
+ }
+
+ public BoundContentPage ()
+ {
+ Title ="Bound Gallery";
+
+ BindingContext = new BoundContentPageViewModel ();
+
+ var button = new Button ();
+ button.SetBinding (Button.TextProperty, "ButtonText");
+ button.SetBinding (Button.CommandProperty, "ButtonCommand");
+
+ SetBinding (NavigationProperty, new Binding ("Navigation", converter: new NavWrapperConverter ()));
+
+ Content = button;
+ }
+ }
+}