+
+
+
+
+ ]]>
+ ]]>
+
+
+
+ Red
+
+]]>
+
+ (
+ // o => o.Foo, default (string)
+ // );
+
+ public string BoundName
+ {
+ get { return (string) GetValue (BoundNameProperty); }
+ set { SetValue (BoundNameProperty, value); }
+ }
+}
+ ]]>
+
+
+
+
+ (w => w.My, default(string));
+
+ public string My {
+ get { return (string)GetValue (MyProperty); }
+ set { SetValue (MyProperty, value); }
+ }
+}
+ ]]>
+
+ (w => w.My, default(string));
+
+ public string My {
+ get { return (string)GetValue (MyProperty); }
+ set { SetValue (MyProperty, value); }
+ }
+}
+ ]]>
+ (w => w.My, default(string));
+ public static readonly BindableProperty MyProperty = MyPropertyKey.BindableProperty;
+
+ public string My {
+ get { return (string)GetValue (MyProperty); }
+ internal set { SetValue (MyPropertyKey, value); }
+ }
+}
+ ]]>
+
+ (Label.TextProperty, vm => vm.Name); // "Name" is the property on the view model
+label.BindingContext = vm;
+
+Debug.WriteLine (label.Text); // prints "John Doe"
+ ]]>
+ (w => w.Foo, default(string));
+
+ public static readonly BindableProperty FooProperty = FooPropertyKey.BindableProperty;
+
+ public string Foo {
+ get { return (string)GetValue (FooProperty); }
+ internal set { SetValue (FooPropertyKey, value); }
+ }
+}
+ ]]>
+
+ (vm => vm.Name));
+Debug.WriteLine (label.Text); //prints "John Doe".
+ ]]>
+
+ ]]>
+ (Label.TextProperty, vm => vm.Name, mode: BindingMode.OneWay);
+
+viewmodel.Name = "John Doe";
+Debug.WriteLine (label.Text); //prints ""
+label.Text = "Foo";
+Debug.WriteLine (viewmodel.Name); //prints "John Doe"
+
+
+//BindingMode.TwoWay
+label = new Label ();
+label.BindingContext = viewmodel = new PersonViewModel ();
+label.SetBinding (Label.TextProperty, vm => vm.Name, mode: BindingMode.TwoWay);
+
+viewmodel.Name = "John Doe";
+Debug.WriteLine (label.Text); //prints "John Doe"
+label.Text = "Foo";
+Debug.WriteLine (viewmodel.Name); //prints "Foo"
+
+
+//BindingMode.OneWayToSource
+label = new Label ();
+label.BindingContext = viewmodel = new PersonViewModel ();
+label.SetBinding (Label.TextProperty, vm => vm.Name, mode: BindingMode.OneWayToSource);
+
+viewmodel.Name = "John Doe";
+Debug.WriteLine (label.Text); //prints ""
+label.Text = "Foo";
+Debug.WriteLine (viewmodel.Name); //prints "Foo"
+ ]]>
+ ]]>
+
+
+]]>
+
+]]>
+
+
+]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ]]>
+ pages = new List (0);
+Color[] colors = { Color.Red, Color.Green, Color.Blue };
+foreach (Color c in colors) {
+ pages.Add (new ContentPage { Content = new StackLayout {
+ Children = {
+ new Label { Text = c.ToString () },
+ new BoxView {
+ Color = c,
+ VerticalOptions = LayoutOptions.FillAndExpand
+ }
+ }
+ }
+ });
+}
+
+MainPage = new CarouselPage {
+ Children = { pages [0],
+ pages [1],
+ pages [2] }
+};
+]]>
+
+
+
+
+
+
+]]>
+
+
+
+
+
+]]>
+ Debug.WriteLine ("Command executed"));
+var button = new Button {
+ Text = "Hit me to execute the command",
+ Command = command,
+};
+]]>
+ Debug.WriteLine ("Command executed: {0}", o));
+var button = new Button {
+ Text = "Hit me to execute the command",
+ Command = command,
+ CommandParameter = "button0",
+};
+]]>
+
+
+
+
+ ]]>
+This is equivalent to the following, more explicit XAML
+
+
+
+
+
+ ]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+]]>
+
+
+ yyyy-MM-dd
+
+
+
+ Jan 1 2000
+
+
+
+
+
+
+ Dec 31 2050
+
+
+
+
+ ]]>
+ (DependencyFetchTarget.NewInstance);
+ ]]>
+ {
+ label.Text = "Async operation completed";
+});
+ ]]>
+ label.Font = Font.OfSize ("HelveticaNeue-UltraLight", NamedSize.Large));
+ ]]>
+
+
+{
+ // do something every 60 seconds
+ Device.BeginInvokeOnMainThread (() =>
+ {
+ // interact with UI elements
+ });
+ return true; // runs again, or false to stop
+});
+ ]]>
+
+
+
+
+
+
+{
+ protected override void Invoke(Entry sender)
+ {
+ Color[] color ={ Color.Red,
+ Color.Orange,
+ Color.Yellow,
+ Color.Green,
+ Color.Blue,
+ Color.Indigo,
+ Color.Violet };
+ sender.TextColor = color[sender.Text.Length % color.Length];
+ }
+}]]>
+
+
+
+
+
+
+
+
+
+
+
+
+ ]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+ people = new List
+ {
+ new Person("Abigail", new DateTime(1975, 1, 15), Color.Aqua),
+ new Person("Bob", new DateTime(1976, 2, 20), Color.Black),
+ // ...etc.,...
+ new Person("Yvonne", new DateTime(1987, 1, 10), Color.Purple),
+ new Person("Zachary", new DateTime(1988, 2, 5), Color.Red)
+ };
+
+ // Create the ListView.
+ ListView listView = new ListView
+ {
+ // Source of data items.
+ ItemsSource = people,
+
+ // Define template for displaying each item.
+ // (Argument of DataTemplate constructor is called for
+ // each item; it must return a Cell derivative.)
+ ItemTemplate = new DataTemplate(() =>
+ {
+ // Create views with bindings for displaying each property.
+ Label nameLabel = new Label();
+ nameLabel.SetBinding(Label.TextProperty, "Name");
+
+ Label birthdayLabel = new Label();
+ birthdayLabel.SetBinding(Label.TextProperty,
+ new Binding("Birthday", BindingMode.OneWay,
+ null, null, "Born {0:d}"));
+
+ BoxView boxView = new BoxView();
+ boxView.SetBinding(BoxView.ColorProperty, "FavoriteColor");
+
+ // Return an assembled ViewCell.
+ return new ViewCell
+ {
+ View = new StackLayout
+ {
+ Padding = new Thickness(0, 5),
+ Orientation = StackOrientation.Horizontal,
+ Children =
+ {
+ boxView,
+ new StackLayout
+ {
+ VerticalOptions = LayoutOptions.Center,
+ Spacing = 0,
+ Children =
+ {
+ nameLabel,
+ birthdayLabel
+ }
+ }
+ }
+ }
+ };
+ })
+ };
+
+ // Accomodate iPhone status bar.
+ this.Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5);
+
+ // Build the page.
+ this.Content = new StackLayout
+ {
+ Children =
+ {
+ header,
+ listView
+ }
+ };
+ }
+ }
+}
+
+]]>
+
+
+ {
+ public Group (string firstInitial)
+ {
+ FirstInitial = firstInitial;
+ }
+
+ public string FirstInitial
+ {
+ get;
+ private set;
+ }
+ }
+ ]]>
+
+
+
+{
+ public Group (string firstInitial)
+ {
+ FirstInitial = firstInitial;
+ }
+
+ public string FirstInitial
+ {
+ get;
+ private set;
+ }
+}
+ ]]>
+
+
+
+
+
+
+
+
+
+]]>
+
+
+
+ ]]>
+ (subscriber, "IntPropertyMessage", (s, e) => {
+ subscriber.IntProperty = e;
+});
+
+//...later...
+
+MessagingCenter.Send(this, "IntPropertyMessage", 2);
+Assert.AreEqual(2, subscriber.IntProperty);
+ ]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ]]>
+ {
+
+ GL.ClearColor (red, green, blue, 1.0f);
+ GL.Clear ((ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit));
+
+ red += 0.01f;
+ if (red >= 1.0f)
+ red -= 1.0f;
+ green += 0.02f;
+ if (green >= 1.0f)
+ green -= 1.0f;
+ blue += 0.03f;
+ if (blue >= 1.0f)
+ blue -= 1.0f;
+ };
+
+ toggle.Toggled += (s, a) => {
+ view.HasRenderLoop = toggle.IsToggled;
+ };
+ button.Clicked += (s, a) => view.Display ();
+
+ var stack = new StackLayout {
+ Padding = new Size (20, 20),
+ Children = {view, toggle, button}
+ };
+
+ Content = stack;
+ }
+ }
+}
+
+ ]]>
+ {
+
+ GL.ClearColor (red, green, blue, 1.0f);
+ GL.Clear ((ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit));
+
+ red += 0.01f;
+ if (red >= 1.0f)
+ red -= 1.0f;
+ green += 0.02f;
+ if (green >= 1.0f)
+ green -= 1.0f;
+ blue += 0.03f;
+ if (blue >= 1.0f)
+ blue -= 1.0f;
+ };
+ ]]>
+ nameToColor = new Dictionary
+ {
+ { "Aqua", Color.Aqua }, { "Black", Color.Black },
+ { "Blue", Color.Blue }, { "Fuchsia", Color.Fuchsia },
+ { "Gray", Color.Gray }, { "Green", Color.Green },
+ { "Lime", Color.Lime }, { "Maroon", Color.Maroon },
+ { "Navy", Color.Navy }, { "Olive", Color.Olive },
+ { "Purple", Color.Purple }, { "Red", Color.Red },
+ { "Silver", Color.Silver }, { "Teal", Color.Teal },
+ { "White", Color.White }, { "Yellow", Color.Yellow }
+ };
+
+ public PickerDemoPage()
+ {
+ Label header = new Label
+ {
+ Text = "Picker",
+ FontSize = Device.GetNamedSize (NamedSize.Large, typeof(Label)),
+ HorizontalOptions = LayoutOptions.Center
+ };
+
+ Picker picker = new Picker
+ {
+ Title = "Color",
+ VerticalOptions = LayoutOptions.CenterAndExpand
+ };
+
+ foreach (string colorName in nameToColor.Keys)
+ {
+ picker.Items.Add(colorName);
+ }
+
+ // Create BoxView for displaying picked Color
+ BoxView boxView = new BoxView
+ {
+ WidthRequest = 150,
+ HeightRequest = 150,
+ HorizontalOptions = LayoutOptions.Center,
+ VerticalOptions = LayoutOptions.CenterAndExpand
+ };
+
+ picker.SelectedIndexChanged += (sender, args) =>
+ {
+ if (picker.SelectedIndex == -1)
+ {
+ boxView.Color = Color.Default;
+ }
+ else
+ {
+ string colorName = picker.Items[picker.SelectedIndex];
+ boxView.Color = nameToColor[colorName];
+ }
+ };
+
+ // Accomodate iPhone status bar.
+ this.Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5);
+
+ // Build the page.
+ this.Content = new StackLayout
+ {
+ Children =
+ {
+ header,
+ picker,
+ boxView
+ }
+ };
+
+ }
+ }
+}
+]]>
+
+
+
+
+
+
+
+
+
+
+]]>
+
+
+
+
+
+
+
+
+
+]]>
+
+ {resultsLabel.Text = "Result: " + searchBar.Text + " is what you asked for.";})
+ };
+
+ MainPage = new ContentPage {
+ Content = new StackLayout {
+ VerticalOptions = LayoutOptions.Start,
+ Children = {
+ new Label {
+ HorizontalTextAlignment = TextAlignment.Center,
+ Text = "SearchBar",
+ FontSize = 50
+ },
+ searchBar,
+ new ScrollView
+ {
+ Content = resultsLabel,
+ VerticalOptions = LayoutOptions.FillAndExpand
+ }
+ },
+ Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5)
+ }
+ };
+ }
+
+ // OnStart, OnSleep, and OnResume implementations, & etc.
+
+}]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ...
+]]>
+
+ {
+ Grid grid = new Grid { Padding = 10 };
+ grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(0.15, GridUnitType.Star) });
+ grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(0.85, GridUnitType.Star) });
+
+ Image image = new Image { Aspect = Aspect.AspectFill, HeightRequest = 40, WidthRequest = 40 };
+ image.SetBinding(Image.SourceProperty, "ImageUrl");
+ Label nameLabel = new Label { FontAttributes = FontAttributes.Bold };
+ nameLabel.SetBinding(Label.TextProperty, "Name");
+
+ grid.Children.Add(image);
+ grid.Children.Add(nameLabel, 1, 0);
+ return grid;
+ })
+});]]>
+
+ monkey.Name.ToLower().Contains(newValue.ToLower()))
+ .ToList();
+ }
+}
+ ]]>
+
+
+
+
+
+
+ Developers should be aware that implicit styles are only applied to the specific type that is described by
+
+ {
+ return new NamedColorPage ();
+ });
+ }
+ }
+
+ // Data type:
+ class NamedColor
+ {
+ public NamedColor (string name, Color color)
+ {
+ this.Name = name;
+ this.Color = color;
+ }
+
+ public string Name { private set; get; }
+
+ public Color Color { private set; get; }
+
+ public override string ToString ()
+ {
+ return Name;
+ }
+ }
+
+ // Format page
+ class NamedColorPage : ContentPage
+ {
+ public NamedColorPage ()
+ {
+ // This binding is necessary to label the tabs in
+ // the TabbedPage.
+ this.SetBinding (ContentPage.TitleProperty, "Name");
+ // BoxView to show the color.
+ BoxView boxView = new BoxView {
+ WidthRequest = 100,
+ HeightRequest = 100,
+ HorizontalOptions = LayoutOptions.Center
+ };
+ boxView.SetBinding (BoxView.ColorProperty, "Color");
+
+ // Build the page
+ this.Content = boxView;
+ }
+ }
+}
+
+
+]]>
+
+
+
+
+
+
+
+
+]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+]]>
+
+{
+ protected override void Invoke(Entry sender)
+ {
+ sender.TextColor = Color.Red;
+ }
+}]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+]]>
+ image.Opacity = 0.5,
+ NumberOfTapsRequired = 2
+ };
+ image.GestureRecognizers.Add (gestureRecognizer);
+ ]]>
+
+
+ button2.IsEnabled = false;
+ }
+ }
+ ]]>
+
+
+
+
+
+
+
+
+
+
+
+
+]]>
+ ]]>
+
+