XAML:
CS:
using System.Windows.Controls.DataVisualization.Charting;
private void Window_Loaded(object sender, RoutedEventArgs e) {
mcChart.LegendTitle = "Legende";
ColumnSeries cs1 = ((ColumnSeries)mcChart.Series[0]);
cs1.ItemsSource =
new KeyValuePair[]{
new KeyValuePair("M1", 100),
new KeyValuePair("M2", 130),
new KeyValuePair("M3", 150),
new KeyValuePair("M4", 125),
new KeyValuePair("M5",155) };
ColumnSeries cs2 = ((ColumnSeries)mcChart.Series[1]);
cs2.ItemsSource =
new KeyValuePair[]{
new KeyValuePair("M1", 110),
new KeyValuePair("M2", 140),
new KeyValuePair("M3", 250),
new KeyValuePair("M4", 325),
new KeyValuePair("M5",155) };
}
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);
}