コード例 #1
0
ファイル: ColourPoint.cs プロジェクト: cdwcgt/Mapping_Tools
        private ContextMenu GetContextMenu(ComboColourProject colourSource)
        {
            var cm = new ContextMenu();

            if (colourSource.ComboColours.Count == 0)
            {
                cm.Items.Add(new MenuItem
                {
                    Header = "Add at least one combo colour before adding colours to this sequence."
                });
            }
            else
            {
                foreach (var comboColour in colourSource.ComboColours)
                {
                    cm.Items.Add(new MenuItem {
                        Header = comboColour.Name,
                        Icon   = new PackIcon
                        {
                            Kind = PackIconKind.Circle, Foreground = new SolidColorBrush(comboColour.Color)
                        },
                        Command = new CommandImplementation(_ => {
                            ColourSequence.Add(comboColour);
                        }),
                        Tag = comboColour
                    });
                }
            }

            return(cm);
        }
コード例 #2
0
ファイル: ColourPoint.cs プロジェクト: cdwcgt/Mapping_Tools
        public ColourPoint(double time, IEnumerable <SpecialColour> colourSequence, ColourPointMode mode, ComboColourProject parentProject)
        {
            Time           = time;
            ColourSequence = new ObservableCollection <SpecialColour>(colourSequence);
            Mode           = mode;
            ParentProject  = parentProject;


            AddCommand = new CommandImplementation(sender => {
                var cm             = GetContextMenu(ParentProject);
                cm.PlacementTarget = sender as Button;
                cm.IsOpen          = true;
            });

            RemoveCommand = new CommandImplementation(item => {
                if (ColourSequence.Count == 0)
                {
                    return;
                }
                if (item == null)
                {
                    ColourSequence.RemoveAt(ColourSequence.Count - 1);
                }
                else
                {
                    ColourSequence.Remove(item as SpecialColour);
                }
            });
        }