예제 #1
0
        public SettingsPage()
        {
            ViewModel.SaveCompleted += HandleSaveCompleted;
            ViewModel.SaveFailed    += HandleSaveFailed;

            var usernameLabel = new MediumBlueLabel(_gitHubUserName);

            var usernameEntry = new SettingsEntry(_gitHubUserName)
            {
                ReturnType    = ReturnType.Next,
                ReturnCommand = new Command(() => _tokenEntry.Focus())
            };

            usernameEntry.SetBinding(Xamarin.Forms.Entry.TextProperty, nameof(ViewModel.UsernameEntryText));

            var tokenLabel = new MediumBlueLabel(_gitHubApiToken);

            _tokenEntry = new SettingsEntry(_gitHubApiToken)
            {
                IsPassword = true,
                ReturnType = ReturnType.Go
            };
            _tokenEntry.SetBinding(Xamarin.Forms.Entry.TextProperty, nameof(ViewModel.TokenEntryText));
            _tokenEntry.SetBinding(Xamarin.Forms.Entry.ReturnCommandProperty, nameof(ViewModel.SaveCommand));

            var saveButton = new BlueButton {
                Text = "Save"
            };

            saveButton.SetBinding(Button.CommandProperty, nameof(ViewModel.SaveCommand));

            var cancelButton = new BlueButton {
                Text = "Cancel"
            };

            cancelButton.Clicked += HandleCancelButtonClicked;

            On <iOS>().SetUseSafeArea(true);

            BackgroundColor = ColorConstants.LightBlue;

            Title = "Settings";

            Content = new StackLayout
            {
                Padding = new Thickness(20),
                Spacing = 1,

                Children =
                {
                    usernameLabel,
                    usernameEntry,
                    tokenLabel,
                    _tokenEntry,
                    saveButton,
                    cancelButton
                }
            };
        }
예제 #2
0
        public CollectionView ParameterView()
        {
            CollectionView collectionView = new CollectionView()
            {
                ItemsLayout   = new GridItemsLayout(1, ItemsLayoutOrientation.Vertical),
                SelectionMode = SelectionMode.None
            };

            collectionView.ItemsSource = new ObservableCollection <ParameterBinding>(); // CollectionView contains ParameterBindings with bindings set in ItemTemplate, ugh!

            collectionView.ItemTemplate = new DataTemplate(() => {                      // CollectionView contains ParameterBindings with bindings set in ItemTemplate, ugh!
                Grid grid = new Grid {
                    Padding = 2
                };
                grid.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(ParameterItemHeight)
                });
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = GridLength.Auto
                });
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = 75
                });
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = GridLength.Auto
                });

                Xamarin.Forms.Entry slider = new Xamarin.Forms.Entry {
                    FontSize = 10, FontAttributes = FontAttributes.Bold, VerticalTextAlignment = TextAlignment.Center
                };
                slider.SetBinding(Xamarin.Forms.Entry.TextProperty, "Value"); // property of ParameterBinding, ugh!
                slider.TextChanged += (object source, TextChangedEventArgs e) => {
                    if (slider.BindingContext == null)
                    {
                        return;
                    }
                    ParameterBinding parameterBinding = (ParameterBinding)slider.BindingContext; // the implicit binding context, ugh!
                    lock (KControls.parameterLock) {
                        if ((!KControls.parameterStateDict.ContainsKey(parameterBinding.Parameter)) || (!KControls.parameterInfoDict.ContainsKey(parameterBinding.Parameter)))
                        {
                            return;
                        }
                        ParameterInfo info             = KControls.parameterInfoDict[parameterBinding.Parameter];
                        KControls.ParameterState state = KControls.parameterStateDict[parameterBinding.Parameter];
                        try { state.value = double.Parse((source as Xamarin.Forms.Entry).Text); } catch { }
                        info.drawn = state.value;
                        parameterBinding.Format = info.ParameterLabel();
                        //RefreshParameters(); // No longer needed, and it now seems to mess up the rows. OLD: otherwise formatLabel does not update even though it has a data binding, ugh!
                    }
                };

                Switch switcher = new Switch();
                switcher.SetBinding(Switch.IsToggledProperty, "Locked"); // property of ParameterBinding, ugh!
                switcher.Toggled += (object source, ToggledEventArgs e) => {
                    if (switcher.BindingContext == null)
                    {
                        return;                                                                    // ugh!
                    }
                    ParameterBinding parameterBinding = (ParameterBinding)switcher.BindingContext; // the implicit binding context, ugh!
                    lock (KControls.parameterLock) {
                        if (!KControls.parameterInfoDict.ContainsKey(parameterBinding.Parameter))
                        {
                            return;
                        }
                        ParameterInfo parameterInfo = KControls.parameterInfoDict[parameterBinding.Parameter];
                        parameterInfo.locked        = (source as Switch).IsToggled;
                    }
                };

                Label formatLabel = new Label {
                    FontSize = 12, FontAttributes = FontAttributes.Bold, VerticalTextAlignment = TextAlignment.Center
                };
                formatLabel.SetBinding(Label.TextProperty, "Format"); // property of ParameterBinding, ugh!

                grid.Children.Add(switcher, 0, 0);
                grid.Children.Add(slider, 1, 0);
                grid.Children.Add(formatLabel, 2, 0);

                return(grid);
            });

            return(collectionView);
        }