Click here to Skip to main content
15,895,084 members
Articles / Operating Systems / Windows

WPF Chart Control With Pan, Zoom and More

Rate me:
Please Sign up or sign in to vote.
4.92/5 (42 votes)
10 Dec 2012Public Domain10 min read 387.7K   10.9K   174  
Chart Control for Microsoft .NET 3.0/WPF with pan, zoom, and offline rendering to the clipboard for custom sizes.
// ****************************************************************************
// Copyright Swordfish Computing Australia 2006                              **
// http://www.swordfish.com.au/                                              **
//                                                                           **
// Filename: Swordfish.WPF.Charts\CopyToClipboard.xaml.cs                    **
// Authored by: John Stewien of Swordfish Computing                          **
// Date: April 2006                                                          **
//                                                                           **
// - Change Log -                                                            **
//*****************************************************************************

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;

namespace Swordfish.WPF.Charts
{
	/// <summary>
	/// Interaction logic for UIElementToClipboard.xaml
	/// </summary>

	public partial class CopyToClipboard : UserControl
	{
		public delegate void CopyToClipboardDelegateType(FrameworkElement target, double width, double height);

		public CopyToClipboardDelegateType CopyToClipboardDelegate;

		public CopyToClipboard()
		{
			InitializeComponent();
			copyOptions.Visibility = Visibility.Collapsed;
			this.MouseEnter += new MouseEventHandler(UIElementToClipboard_MouseEnter);
			this.MouseLeave += new MouseEventHandler(UIElementToClipboard_MouseLeave);
			CopyToClipboardDelegate = ChartUtilities.CopyFrameworkElementToClipboard;
		}

		// Using a DependencyProperty as the backing store for Text.  This enables animation, styling, binding, etc...
		public static readonly DependencyProperty CopyTargetProperty =
			DependencyProperty.Register("CopyTarget", typeof(FrameworkElement), typeof(CopyToClipboard), new UIPropertyMetadata(null));

		public FrameworkElement CopyTarget
		{
			get
			{
				return (FrameworkElement)GetValue(CopyTargetProperty);
			}
			set
			{
				SetValue(CopyTargetProperty, value);
			}
		}

		void UIElementToClipboard_MouseLeave(object sender, MouseEventArgs e)
		{
			copyOptions.Visibility = Visibility.Collapsed;
			this.Margin = new Thickness(0,0,0,0);
		}

		void UIElementToClipboard_MouseEnter(object sender, MouseEventArgs e)
		{
			copyOptions.Visibility = Visibility.Visible;
			this.Margin = new Thickness(0,0,0,8);
		}

		void bCopy640x480_Click(object sender, RoutedEventArgs e)
		{
			CopyToClipboardDelegate(CopyTarget, 640, 480);
		}
		void bCopy800x600_Click(object sender, RoutedEventArgs e)
		{
			CopyToClipboardDelegate(CopyTarget, 800, 600);
		}
		void bCopy1024x768_Click(object sender, RoutedEventArgs e)
		{
			CopyToClipboardDelegate(CopyTarget, 1024, 768);
		}
		void bCopy1280x1024_Click(object sender, RoutedEventArgs e)
		{
			CopyToClipboardDelegate(CopyTarget, 1280, 1024);
		}
		void bCopyCustom_Click(object sender, RoutedEventArgs e)
		{
			double width = 640;
			double height = 480;
			Double.TryParse(tbWidth.Text, out width);
			Double.TryParse(tbHeight.Text, out height);
			CopyToClipboardDelegate(CopyTarget, width, height);
		}
	}
}

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 A Public Domain dedication


Written By
Founder Cheesy Design
Taiwan Taiwan
John graduated from the University of South Australia in 1997 with a Bachelor of Electronic Engineering Degree, and since then he has worked on hardware and software in many fields including Aerospace, Defence, and Medical giving him over 10 of years experience in C++ and C# programming. In 2009 John Started his own contracting company doing business between Taiwan and Australia.

Comments and Discussions