日期:2014-05-20  浏览次数:20750 次

在用WPF Elements 时我用下面的代码显示图像,但是结果只是一个带标题的空的页面,是哪里出了问题吗?由于图片传不上来,附代码,求牛人指点
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using Mindscape.WpfElements.Charting;

namespace WpfApplication2
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            Image myImage = new Image();
            myImage.Source = GetBitmap();

            Grid myStackPanel = new Grid();
            myStackPanel.Children.Add(myImage);
            this.Content = myStackPanel;
        }

        public RenderTargetBitmap GetBitmap()
        {
            int height, width;
            height = 800;
            width = 800;
            var size = new Size(height, width);

            Grid mainContainer = new Grid();
            mainContainer.HorizontalAlignment = HorizontalAlignment.Stretch;
            mainContainer.VerticalAlignment = VerticalAlignment.Stretch;

            Chart ch = new Chart();
            ch.HorizontalAlignment = HorizontalAlignment.Stretch;
            ch.VerticalAlignment = VerticalAlignment.Stretch;

            var d = new LineSeries();
            var ps = new List<Point>();
            ps.Add(new Point(0, 0));
            ps.Add(new Point(10, 10));
            ps.Add(new Point(20, 20));
            d.ItemsSource = ps;         
            ch.Series.Add(d);
            ch.Title = "Test";