using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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;
// Reference Assemblies / Framework
// System.Windows.Controls.DataVisualization.Toolkit
using System.Windows.Controls.DataVisualization.Charting;
namespace Chart_Bubbles {
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e) {
List liste1 = new List();
liste1.Add(new BubblePoint() { X = 1, Y = 10, R = 40 });
liste1.Add(new BubblePoint() { X = 4, Y = 10, R = 30 });
liste1.Add(new BubblePoint() { X = 4, Y = 4, R = 40 });
liste1.Add(new BubblePoint() { X = 8, Y = 8, R = 20 });
liste1.Add(new BubblePoint() { X = 10, Y = 1, R = 50 });
mcChart.LegendTitle = "Legende";
((BubbleSeries)mcChart.Series[0]).ItemsSource = liste1;
List liste2 = new List();
liste2.Add(new BubblePoint() { X = 1, Y = 4, R = 10 });
liste2.Add(new BubblePoint() { X = 2, Y = 5, R = 30 });
liste2.Add(new BubblePoint() { X = 4, Y = 4, R = 12 });
liste2.Add(new BubblePoint() { X = 7, Y = 2, R = 70 });
liste2.Add(new BubblePoint() { X = 10, Y = 8, R = 25 });
mcChart.LegendTitle = "Legende";
((BubbleSeries)mcChart.Series[1]).ItemsSource = liste2;
} // Window_Loaded
private class BubblePoint {
public double X { get; set; }
public double Y { get; set; }
public double R { get; set; }
}
private void bnChart2Clipboard_Click(object sender, RoutedEventArgs e) {
CopyUIElementToClipboard(mcChart);
}
// source: http://elegantcode.com/2010/12/13/wpfcopy-uielement-to-clipboard-as-multiple-formats/
public static void CopyUIElementToClipboard(FrameworkElement element) {
//data object to hold our different formats representing the element
DataObject dataObject = new DataObject();
//lets start with the text representation
//to make is easy we will just assume the object set as the DataContext has the ToString method overrideen and we use that as the text
dataObject.SetData(DataFormats.Bitmap, element, true);
//now lets do the image representation
double width = element.ActualWidth;
double height = element.ActualHeight;
RenderTargetBitmap bmpCopied = new RenderTargetBitmap((int)Math.Round(width), (int)Math.Round(height), 96, 96, PixelFormats.Default);
DrawingVisual dv = new DrawingVisual();
using (DrawingContext dc = dv.RenderOpen()) {
VisualBrush vb = new VisualBrush(element);
dc.DrawRectangle(vb, null, new Rect(new Point(), new Size(width, height)));
}
bmpCopied.Render(dv);
dataObject.SetData(DataFormats.Bitmap, bmpCopied, true);
//now place our object in the clipboard
Clipboard.SetDataObject(dataObject, true);
}
}
}