|
| 1 | +using System.Collections.ObjectModel; |
| 2 | +using Xamarin.Forms; |
| 3 | + |
| 4 | +namespace DataBindingDemos |
| 5 | +{ |
| 6 | + public class MultiBindingConverterCodePage : ContentPage |
| 7 | + { |
| 8 | + public MultiBindingConverterCodePage() |
| 9 | + { |
| 10 | + BindingContext = new GroupViewModel(); |
| 11 | + |
| 12 | + Grid grid = new Grid { Margin = new Thickness(20) }; |
| 13 | + |
| 14 | + grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }); |
| 15 | + grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }); |
| 16 | + grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }); |
| 17 | + grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }); |
| 18 | + grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }); |
| 19 | + grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }); |
| 20 | + |
| 21 | + grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(0.75, GridUnitType.Star) }); |
| 22 | + grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(0.25, GridUnitType.Star) }); |
| 23 | + |
| 24 | + grid.Children.Add(new Label { Text = "Employee", FontAttributes = FontAttributes.Bold }); |
| 25 | + grid.Children.Add(new Label { Text = "Can drive?", FontAttributes = FontAttributes.Bold }, 1, 0); |
| 26 | + |
| 27 | + Label employee1 = new Label { VerticalTextAlignment = TextAlignment.Center }; |
| 28 | + employee1.SetBinding(Label.TextProperty, "Employee1.FullName"); |
| 29 | + |
| 30 | + CheckBox checkBox1 = new CheckBox { HorizontalOptions = LayoutOptions.End }; |
| 31 | + checkBox1.SetBinding(CheckBox.IsCheckedProperty, new MultiBinding |
| 32 | + { |
| 33 | + Bindings = new Collection<BindingBase> |
| 34 | + { |
| 35 | + new Binding("Employee1.IsOver16"), |
| 36 | + new Binding("Employee1.HasPassedTest"), |
| 37 | + new Binding("Employee1.IsSuspended", converter: new InverterConverter()) |
| 38 | + }, |
| 39 | + Converter = new AllTrueMultiConverter() |
| 40 | + }); |
| 41 | + |
| 42 | + Label employee2 = new Label { VerticalTextAlignment = TextAlignment.Center }; |
| 43 | + employee2.SetBinding(Label.TextProperty, "Employee2.FullName"); |
| 44 | + |
| 45 | + CheckBox checkBox2 = new CheckBox { HorizontalOptions = LayoutOptions.End }; |
| 46 | + checkBox2.SetBinding(CheckBox.IsCheckedProperty, new MultiBinding |
| 47 | + { |
| 48 | + Bindings = new Collection<BindingBase> |
| 49 | + { |
| 50 | + new Binding("Employee2.IsOver16"), |
| 51 | + new Binding("Employee2.HasPassedTest"), |
| 52 | + new Binding("Employee2.IsSuspended", converter: new InverterConverter()) |
| 53 | + }, |
| 54 | + Converter = new AllTrueMultiConverter() |
| 55 | + }); |
| 56 | + |
| 57 | + Label employee3 = new Label { VerticalTextAlignment = TextAlignment.Center }; |
| 58 | + employee3.SetBinding(Label.TextProperty, "Employee3.FullName"); |
| 59 | + |
| 60 | + CheckBox checkBox3 = new CheckBox { HorizontalOptions = LayoutOptions.End }; |
| 61 | + checkBox3.SetBinding(CheckBox.IsCheckedProperty, new MultiBinding |
| 62 | + { |
| 63 | + Bindings = new Collection<BindingBase> |
| 64 | + { |
| 65 | + new Binding("Employee3.IsOver16"), |
| 66 | + new Binding("Employee3.HasPassedTest"), |
| 67 | + new Binding("Employee3.IsSuspended", converter: new InverterConverter()) |
| 68 | + }, |
| 69 | + Converter = new AllTrueMultiConverter() |
| 70 | + }); |
| 71 | + |
| 72 | + Label employee4 = new Label { VerticalTextAlignment = TextAlignment.Center }; |
| 73 | + employee4.SetBinding(Label.TextProperty, "Employee4.FullName"); |
| 74 | + |
| 75 | + CheckBox checkBox4 = new CheckBox { HorizontalOptions = LayoutOptions.End }; |
| 76 | + checkBox4.SetBinding(CheckBox.IsCheckedProperty, new MultiBinding |
| 77 | + { |
| 78 | + Bindings = new Collection<BindingBase> |
| 79 | + { |
| 80 | + new Binding("Employee4.IsOver16"), |
| 81 | + new Binding("Employee4.HasPassedTest"), |
| 82 | + new Binding("Employee4.IsSuspended", converter: new InverterConverter()) |
| 83 | + }, |
| 84 | + Converter = new AllTrueMultiConverter() |
| 85 | + }); |
| 86 | + |
| 87 | + Label employee5 = new Label { VerticalTextAlignment = TextAlignment.Center }; |
| 88 | + employee5.SetBinding(Label.TextProperty, "Employee5.FullName"); |
| 89 | + |
| 90 | + CheckBox checkBox5 = new CheckBox { HorizontalOptions = LayoutOptions.End }; |
| 91 | + checkBox5.SetBinding(CheckBox.IsCheckedProperty, new MultiBinding |
| 92 | + { |
| 93 | + Bindings = new Collection<BindingBase> |
| 94 | + { |
| 95 | + new Binding("Employee5.IsOver16"), |
| 96 | + new Binding("Employee5.HasPassedTest"), |
| 97 | + new Binding("Employee5.IsSuspended", converter: new InverterConverter()) |
| 98 | + }, |
| 99 | + Converter = new AllTrueMultiConverter() |
| 100 | + }); |
| 101 | + |
| 102 | + grid.Children.Add(employee1, 0, 1); |
| 103 | + grid.Children.Add(checkBox1, 1, 1); |
| 104 | + grid.Children.Add(employee2, 0, 2); |
| 105 | + grid.Children.Add(checkBox2, 1, 2); |
| 106 | + grid.Children.Add(employee3, 0, 3); |
| 107 | + grid.Children.Add(checkBox3, 1, 3); |
| 108 | + grid.Children.Add(employee4, 0, 4); |
| 109 | + grid.Children.Add(checkBox4, 1, 4); |
| 110 | + grid.Children.Add(employee5, 0, 5); |
| 111 | + grid.Children.Add(checkBox5, 1, 5); |
| 112 | + |
| 113 | + Title = "MultiBinding converter demo"; |
| 114 | + Content = grid; |
| 115 | + } |
| 116 | + } |
| 117 | +} |
0 commit comments