Esempio n. 1
0
        private void RefreshParameters()
        {
            // call it with already locked parameterLock
            var parameterList = new ObservableCollection <ParameterBinding>();

            foreach (var kvp in KControls.parameterStateDict)
            {
                ParameterInfo            info             = KControls.parameterInfoDict[kvp.Key];
                KControls.ParameterState state            = KControls.parameterStateDict[kvp.Key];
                ParameterBinding         parameterBinding =
                    new ParameterBinding {
                    Parameter = info.parameter,
                    Format    = info.ParameterLabel(),
                    Value     = state.value.ToString("G4"),
                    Locked    = info.locked,
                };
                parameterList.Add(parameterBinding);
            }
            parameterView.ItemsSource = parameterList;
        }
Esempio n. 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);
        }