现代UI(地铁)图表WPF不显示 [英] Modern UI (Metro) Charts WPF not showing up

查看:333
本文介绍了现代UI(地铁)图表WPF不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的项目使用.NET Framework 4.5和WPF。我需要生成多种类型的图表,因此我想使用 http://modernuicharts.codeplex.com/图书馆做到这一点。我按照那个codeplex页面中的文档: http://modernuicharts.codeplex.com/documentation 并完成步骤。

I'm Using .NET Framework 4.5 and WPF for my project. I need to generate several types of charts so I'm thinking to use http://modernuicharts.codeplex.com/ library to do that. I followed the documentation there in that codeplex page : http://modernuicharts.codeplex.com/documentation and completed the steps.

现在我在Visual Studio 13中没有得到任何错误或警告消息,但只是图表不显示。我只能看到图表的标题和副标题。

Now I'm not getting any kind of errors or warning messages in Visual Studio 13, But simply the chart is not showing up. I can only see the title and the subtitle of the chart.

这个问题的可能原因是什么以及如何更正?

What are the possible causes for this problem and how to correct them?

谢谢

XAML代码:

<Canvas Margin="570,90,29,92" Background="White" >
                <chart:PieChart
        Style="{StaticResource MinimalChartStyle}"
        ChartTitle="Minimal Pie Chart"
        ChartSubTitle="Chart with fixed width and height"
        SelectedItem="{Binding Path=SelectedItem, Mode=TwoWay}" >
                    <chart:PieChart.Series>
                        <chart:ChartSeries
                SeriesTitle="Errors"
                DisplayMember="Category"
                ValueMember="Number"
                ItemsSource="{Binding Path=Errors}" />
                    </chart:PieChart.Series>
                </chart:PieChart>
            </Canvas>

用作dataContext的ViewModel类:

The ViewModel Class which is used as the dataContext :

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ModernUIForWPFSample.WithoutBackButton.Views
{
    public class MainViewModel
    {
        public ObservableCollection<TestClass> Errors { get; private set; }

        public MainViewModel()
        {
            Errors = new ObservableCollection<TestClass>();
            Errors.Add(new TestClass() { Category = "Globalization", Number = 75 });
            Errors.Add(new TestClass() { Category = "Features", Number = 2 });
            Errors.Add(new TestClass() { Category = "ContentTypes", Number = 12 });
            Errors.Add(new TestClass() { Category = "Correctness", Number = 83});
            Errors.Add(new TestClass() { Category = "Best Practices", Number = 29 });
        }

        private object selectedItem = null;
        public object SelectedItem
        {
            get
            {
                return selectedItem;
            }
            set
            {
                // selected item has changed
                selectedItem = value;                
            }
        }
    }

    // class which represent a data point in the chart
    public class TestClass
    {
        public string Category { get; set; }

        public int Number  { get; set; }        
    }

}

在代码Bihind: / p>

In the code Bihind :

public FinalAnalysis()
        {
            InitializeComponent();
            this.DataContext = new MainViewModel();
        }


推荐答案

应用程式XAML:

<Application x:Class="WpfApplication1.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml"
             xmlns:chart="clr-namespace:De.TorstenMandelkow.MetroChart;assembly=De.TorstenMandelkow.MetroChart">
    <Application.Resources>
        <ResourceDictionary>
            <Style x:Key="MinimalChartStyle" TargetType="chart:ChartBase">
                <Setter Property="Width" Value="500"/>
                <Setter Property="Height" Value="500"/>
            </Style>
        </ResourceDictionary>
    </Application.Resources>
</Application>

MainWindow XAML:

MainWindow XAML :

<Window 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        x:Class="WpfApplication1.MainWindow"
        Title="MainWindow" Height="1500" Width="1525"
        xmlns:metroChart="clr-namespace:De.TorstenMandelkow.MetroChart;assembly=De.TorstenMandelkow.MetroChart">


        <metroChart:PieChart
        Style="{StaticResource MinimalChartStyle}"
        ChartTitle="Minimal Pie Chart"
        ChartSubTitle="Chart with fixed width and height"
        SelectedItem="{Binding Path=SelectedItem, Mode=TwoWay}" >
            <metroChart:PieChart.Series>
                <metroChart:ChartSeries
                SeriesTitle="Errors"
                DisplayMember="Category"
                ValueMember="Number"
                ItemsSource="{Binding Path=Errors}" />
            </metroChart:PieChart.Series>
        </metroChart:PieChart>

</Window>

MainWindow cs:

MainWindow cs :

public MainWindow()
{

    InitializeComponent();
    DataContext = new MainViewModel();
}

MainWindowViewModel与您的相同,我不会在这里复制粘贴。请注意程序集声明:

MainWindowViewModel is same as yours, I will not copy paste it here. Pay attention to assembly declaration :

 xmlns:metroChart="clr-namespace:De.TorstenMandelkow.MetroChart;assembly=De.TorstenMandelkow.MetroChart"

,不要忘记在App xaml中添加样式

and do not forget to add the style in App xaml

这篇关于现代UI(地铁)图表WPF不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆