Click here to Skip to main content
13,000,324 members (71,750 online)
Click here to Skip to main content

Stats

280.9K views
4.6K downloads
69 bookmarked
Posted 14 Oct 2010

WPF Charting using MVVM Pattern

, 19 Oct 2010
Shows how to implement a WPF Chart in .NET 4.0 using MVVM Pattern
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Windows.Controls.DataVisualization.Charting;
using System.Windows;
using System.Windows.Controls;

namespace WPFCharting.Commands
{
    class ShowSeries : ICommand
    {
        public bool CanExecute(object parameter)
        {
            return true;
        }
        public void Execute(object parameter)
        {
            string SelectedSeriesName = parameter as string;
            if (SelectedSeriesName == null) return;
            ContentControl TemporaryContentControl = null;
            switch (SelectedSeriesName)
            {
                case "AreaSeries":
                    TemporaryContentControl = ucAreaSeries.getInstance();
                    break;
                case "BarSeries" :
                    TemporaryContentControl = ucBarSeries.getInstance();
                    break;
                case "BubbleSeries" :
                    TemporaryContentControl= ucBubbleSeries.getInstance();
                    break;
                case "ColumnSeries":
                    TemporaryContentControl = ucColumnSeriesChart.getInstance();
                    break;
                case "LineSeries":
                    TemporaryContentControl = ucLineSeries.getInstance();
                    break;
                case "PieSeries":
                    TemporaryContentControl = ucPieSeriesChart.getInstance();
                    break;
                case "ScatterSeries":
                    TemporaryContentControl = ucScatterSeries.getInstance();
                    break;
                default:
                    break;
            }
            (MainWindowVM.getInstance()).MainChart = TemporaryContentControl;
        }

        public event EventHandler CanExecuteChanged;
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Mr. Javaman
Software Developer (Senior)
United States United States
Mr Javaman

You may also be interested in...

Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170624.1 | Last Updated 19 Oct 2010
Article Copyright 2010 by Mr. Javaman
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid