Ejemplo n.º 1
0
 public void OnLegendClick(KSeries[] legend, KSeries series)
 {
     if (guiControls.IsShiftDown())
     {
         KChartHandler.ShiftInvertVisible(series.name);
         foreach (var seriesI in legend)
         {
             seriesI.lineButton.SetLegendImage(seriesI);
         }
     }
     else
     {
         KChartHandler.InvertVisible(series.name);
         series.lineButton.SetLegendImage(series); // accessing the shared series data structure!
     }
     KChartHandler.VisibilityRemember();
     KChartHandler.ChartUpdate(null); // cannot provide style: would have to marshall it throug KGui but is ok to update
 }
Ejemplo n.º 2
0
        public CollectionView LegendView()
        {
            CollectionView collectionView = new CollectionView()
            {
                //ItemsLayout = ListItemsLayout.VerticalList,  // can also be set to a vertical grid
                ItemsLayout   = new GridItemsLayout(2, ItemsLayoutOrientation.Vertical),
                SelectionMode = SelectionMode.Single,
            };

            // collectionView.SetBinding(ItemsView.ItemsSourceProperty, "Monkeys"); // a binding for the ItemSource, but we give keep regenerating it

            collectionView.ItemsSource = new ObservableCollection <LegendItem>(); // CollectionView contains LegendItems with bindings set in ItemTemplate

            collectionView.ItemTemplate = new DataTemplate(() => {                // CollectionView contains LegendItems with bindings set in ItemTemplate
                Grid grid = new Grid {
                    Padding = 2
                };
                grid.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(LegendItemHeight)
                });
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = GridLength.Auto
                });
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = GridLength.Auto
                });
                // grid.ColumnDefinitions.Add(new ColumnDefinition { Width = 50 }); //it is definitely labels that flash a gray box when updated

                BoxView box = new BoxView {
                    VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center
                };                                                       // needed, otherwise the default .Fill option ignores HeightRequest
                box.SetBinding(BoxView.ColorProperty, "Color");          // property of LegendItem
                box.SetBinding(BoxView.HeightRequestProperty, "Height"); // property of LegendItem
                box.SetBinding(BoxView.WidthRequestProperty, "Width");   // property of LegendItem

                Label nameLabel = new Label {
                    FontSize = LegendFontSize, FontAttributes = FontAttributes.Bold
                };
                nameLabel.SetBinding(Label.TextProperty, "Name"); // property of LegendItem

                grid.Children.Add(box, 0, 0);
                grid.Children.Add(nameLabel, 1, 0);
                // grid.Children.Add(new Label { Text = "xxx" }, 2, 0); //it is definitely labels that flash a gray box when updated

                return(grid);
            });

            collectionView.SelectionChanged += (object sender, SelectionChangedEventArgs args) => {
                LegendItem item = collectionView.SelectedItem as LegendItem;
                if (item != null)
                {
                    KChartHandler.InvertVisible(item.Name);
                    KChartHandler.VisibilityRemember();
                    KChartHandler.ChartUpdate(null);
                    KGui.gui.GuiLegendUpdate();
                    collectionView.SelectedItem = null; // avoid some visible flashing of the selection
                }
            };

            return(collectionView);
        }