protected override void OnAppearing()
        {
            base.OnAppearing();

            ViewModel.GetExpenseStatus();


            // dynamically add rows to the TableView
            int count = 0;

            foreach (var es in ViewModel.ExpenseStatuses)
            {
                var cell = new SwitchCell {
                    Text = es.Name
                };

                Binding binding = new Binding
                {
                    Source = ViewModel.ExpenseStatuses[count],
                    Path   = "Status",
                    Mode   = BindingMode.TwoWay
                };
                cell.SetBinding(SwitchCell.OnProperty, binding);

                var section = new TableSection("Statuses");
                section.Add(cell);
                expenseTableView.Root.Add(section);

                count++;
            }
        }
Exemple #2
0
        protected override void OnAppearing()
        {
            base.OnAppearing();

            ViewModel.GetExpenseStatus();

            int count   = 0;
            var section = new TableSection("Statuses");

            foreach (var es in ViewModel.ExpenseStatuses)
            {
                var cell = new SwitchCell {
                    Text = es.Name
                };

                Binding binding = new Binding();
                binding.Source = ViewModel.ExpenseStatuses[count];
                binding.Path   = "Status";
                binding.Mode   = BindingMode.TwoWay;
                cell.SetBinding(SwitchCell.OnProperty, binding);

                section.Add(cell);

                count++;
            }
            expenseTableView.Root.Add(section);
        }
        protected override void OnAppearing()
        {
            base.OnAppearing();

            ViewModel.GetExpenseStatus();

            // enclosing TableSection could be defined in xaml but generated here in C# code-behind - neater in leaving previous xaml layout undisturbed
            var section = new TableSection("Statuses");

            // I'd rather do this with a for loop
            int count = 0;

            foreach (var expenseStatus in ViewModel.ExpenseStatuses)
            {
                var cell = new SwitchCell {
                    Text = expenseStatus.Name
                };
                // simple assignation of cell.On=expenseStatus.Status would *not* be binding ...

                // ... so make a Binding in C# code - cf the xaml way, with Source (to VM) and Path (method or property member eg Observable)
                Binding binding = new Binding();
                binding.Source = ViewModel.ExpenseStatuses[count]; // iterate through each individual row (as per ItemsSource)
                binding.Path   = "Status";                         // bind Path by using string name of property - cf xaml
                binding.Mode   = BindingMode.TwoWay;
                // could set binding.Converter to process boolean to integer a la IEValueConverter
                cell.SetBinding(SwitchCell.OnProperty, binding);

                section.Add(cell);

                count++;
                // i.e. 1 binding for each record in ExpensesStatuses
            }

            expenseTableView.Root.Add(section);     // Add the assembled section (of cells) to the element named expenseTableView
            // NB expenseTableView was a TableView element named with x:Name (hence no C# declaration) - not the done thing in MVVM if binding working ok
        }