[英]Modern UI (Metro) Charts WPF not showing up
我正在為我的項目使用.NET Framework 4.5和WPF。 我需要生成幾種類型的圖表,所以我想使用http://modernuicharts.codeplex.com/庫來做到這一點。 我按照那個codeplex頁面中的文檔: http ://modernuicharts.codeplex.com/documentation完成了這些步驟。
現在我在Visual Studio 13中沒有收到任何類型的錯誤或警告消息,但只是圖表沒有顯示出來。 我只能看到圖表的標題和副標題。
導致此問題的可能原因是什么以及如何糾正?
謝謝
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類:
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中:
public FinalAnalysis()
{
InitializeComponent();
this.DataContext = new MainViewModel();
}
這是一個有效的例子:
App 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:
<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:
public MainWindow()
{
InitializeComponent();
DataContext = new MainViewModel();
}
MainWindowViewModel與你的相同,我不會復制粘貼在這里。 注意裝配申報:
xmlns:metroChart="clr-namespace:De.TorstenMandelkow.MetroChart;assembly=De.TorstenMandelkow.MetroChart"
並且不要忘記在App xaml中添加樣式
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.