Click here to Skip to main content
15,867,835 members
Articles / Desktop Programming / WPF

OpenWPFChart: assembling charts from components: Part I - Parts

Rate me:
Please Sign up or sign in to vote.
4.29/5 (17 votes)
19 Mar 2009CPOL14 min read 81.5K   4K   81  
Provides the component model along with base components to assemble charts.
// <copyright file="PointMarkerDialog.xaml.cs" company="Oleg V. Polikarpotchkin">
// Copyright © 2008 Oleg V. Polikarpotchkin. All Right Reserved
// </copyright>
// <author>Oleg V. Polikarpotchkin</author>
// <email>ov-p@yandex.ru</email>
// <date>2008-12-23</date>
// <summary>OpenWPFChart library. Dialog to select a PointMarker from internal list.</summary>
// <revision>$Id: PointMarkerDialog.xaml.cs 18093 2009-03-16 04:15:06Z unknown $</revision>

using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace OpenWPFChart.Helpers
{
	/// <summary>
	/// Dialog to select a PointMarker from internal list.
	/// </summary>
	public partial class PointMarkerDialog : Window, INotifyPropertyChanged
	{
		public PointMarkerDialog(Color color)
		{
			InitializeComponent();

			strokeColor = color;
			fillColor = color;
			DataContext = this;
		}

		/// <summary>
		/// Gets the marker geometry.
		/// </summary>
		/// <value>The marker geometry.</value>
		public Geometry MarkerGeometry
		{
			get 
			{
				if (btnOK.IsEnabled)
					return lbxMarkers.SelectedItem as Geometry;
				else
					return null; 
			}
		}

		Color strokeColor;
		/// <summary>
		/// Gets or sets the marker stroke color.
		/// </summary>
		/// <value>The color of the marker stroke.</value>
		public Color MarkerStrokeColor
		{
			get { return strokeColor; }
			set
			{
				if (strokeColor != value)
				{
					strokeColor = value;
					Notify("MarkerStrokeColor");
				}
			}
		}

		Color fillColor;
		/// <summary>
		/// Gets or sets the marker fill color.
		/// </summary>
		/// <value>The color of the marker fill.</value>
		public Color MarkerFillColor
		{
			get { return fillColor; }
			set
			{
				if (fillColor != value)
				{
					fillColor = value;
					Notify("MarkerFillColor");
				}
			}
		}

		/// <summary>
		/// Selects the color with System.Windows.Forms.ColorDialog.
		/// </summary>
		/// <param name="color">The WPF color.</param>
		/// <returns></returns>
		private static Color selectColor(Color color)
		{
			System.Windows.Forms.ColorDialog dlg = new System.Windows.Forms.ColorDialog();
			dlg.Color = System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B);
			if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
				return color;
			return Color.FromArgb(dlg.Color.A, dlg.Color.R, dlg.Color.G, dlg.Color.B);
		}

		private void lbxMarkers_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			btnOK.IsEnabled = true;
		}

		private void btnMarkerStrokeColor_Click(object sender, RoutedEventArgs e)
		{
			MarkerStrokeColor = selectColor(MarkerStrokeColor);
		}

		private void btnMarkerFillColor_Click(object sender, RoutedEventArgs e)
		{
			MarkerFillColor = selectColor(MarkerFillColor);
		}

		/// <summary>
		/// Handles the Click event of the btnOK control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
		private void btnOK_Click(object sender, RoutedEventArgs e)
		{
			DialogResult = true;
		}

		#region INotifyPropertyChanged Members
		public event PropertyChangedEventHandler PropertyChanged;
		void Notify(string prop)
		{
			if (PropertyChanged != null)
			{
				PropertyChanged(this, new PropertyChangedEventArgs(prop));
			}
		}
		#endregion
	}
}

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)


Written By
Team Leader
Russian Federation Russian Federation
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions