예제 #1
0
        public UsingPieChartExampleViewModel()
        {
            _oneSelectedSegment = new PieSegmentViewModel {
                Value = 60, Name = "Fruit", IsSelected = true
            };

            SegmentsDataCollection = new ObservableCollection <IPieSegmentViewModel>
            {
                _oneSelectedSegment,
                new PieSegmentViewModel {
                    Value = 46, Name = "Protein"
                },
                new PieSegmentViewModel {
                    Value = 36, Name = "Vegetables"
                },
                new PieSegmentViewModel {
                    Value = 30, Name = "Diary"
                },
                new PieSegmentViewModel {
                    Value = 18, Name = "Grains"
                },
                new PieSegmentViewModel {
                    Value = 10, Name = "Other"
                },
            };

            SelectedSegment = _oneSelectedSegment;

            AddNewItem = new ActionCommand(() =>
            {
                SegmentsDataCollection.Add(new PieSegmentViewModel
                {
                    Value      = NewSegmentValue.ToDouble(),
                    Name       = NewSegmentText,
                    Fill       = ToGradient(((SolidColorBrush)NewSegmentBrush.Brush).Color),
                    Stroke     = ToShade(((SolidColorBrush)NewSegmentBrush.Brush).Color, 0.8),
                    IsSelected = true,
                });
            }, () =>
            {
                return(!NewSegmentText.IsNullOrEmpty() && (!NewSegmentValue.IsNullOrEmpty() && NewSegmentValue.ToDouble() > 0) && NewSegmentBrush != null);
            });

            DeleteSegment           = new ActionCommand(() => { SegmentsDataCollection.RemoveAt(0); });
            SegmentSelectionCommand = new ActionCommand <NotifyCollectionChangedEventArgs>(OnSegmentSelectionExecute);
        }
예제 #2
0
        public UsingDonutChartExampleViewModel()
        {
            _donutModels = new ObservableCollection <IPieSegmentViewModel>
            {
                new DonutSegmentViewModel {
                    Value = 48, Name = "Rent", Stroke = ToShade(Colors.Orange, 0.8), Fill = ToGradient(Colors.Orange), StrokeThickness = 2
                },
                new DonutSegmentViewModel {
                    Value = 19, Name = "Food", Stroke = ToShade(Colors.Green, 0.8), Fill = ToGradient(Colors.Green), StrokeThickness = 2
                },
                new DonutSegmentViewModel {
                    Value = 9, Name = "Utilities", Stroke = ToShade(Colors.DodgerBlue, 0.8), Fill = ToGradient(Colors.DodgerBlue), StrokeThickness = 2
                },
                new DonutSegmentViewModel {
                    Value = 9, Name = "Fun", Stroke = ToShade(Colors.Gray, 0.8), Fill = ToGradient(Colors.Gray), StrokeThickness = 2
                },
                new DonutSegmentViewModel {
                    Value = 10, Name = "Clothes", Stroke = ToShade(Colors.Firebrick, 0.8), Fill = ToGradient(Colors.Firebrick), StrokeThickness = 2
                },
                new DonutSegmentViewModel {
                    Value = 5, Name = "Phone", Stroke = ToShade(Colors.DarkSalmon, 0.8), Fill = ToGradient(Colors.DarkSalmon), StrokeThickness = 2
                }
            };

            AddNewItemCommand = new ActionCommand(() =>
            {
                _donutModels.Add(new DonutSegmentViewModel
                {
                    Value  = NewSegmentValue.ToDouble(),
                    Name   = NewSegmentText,
                    Fill   = ToGradient(((SolidColorBrush)NewSegmentBrush.Brush).Color),
                    Stroke = ToShade(((SolidColorBrush)NewSegmentBrush.Brush).Color, 0.8)
                });
            }, () =>
            {
                return(!NewSegmentText.IsNullOrEmpty() && (!NewSegmentValue.IsNullOrEmpty() && NewSegmentValue.ToDouble() > 0) && NewSegmentBrush != null);
            });

            SegmentSelectionCommand = new ActionCommand <NotifyCollectionChangedEventArgs>(OnSegmentSelectionExecute);
        }