So I'm trying to use Torsten Mandelkow ModernUICharts
NuGet package.
I was able to follow the documentation on his Codeplex in a new solution and the chart showed up and populated with no problem. The issue is when I try to do it inside my project I get the error message:
The type reference cannot find a public type named 'ChartBase'. Line 18 Position 75.
I've ensured that I've copied the code between the two projects exactly multiple times but I keep getting the same result. I've tried looking it up on Stack Overflow 1 2 3 4 with no success.
Here is my code:
App.xaml
<Application x:Class="ReqTotalWPF.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:chart="clr-namespace:De.TorstenMandelkow.MetroChart;assembly=De.TorstenMandelkow.MetroChart"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<!-- Accent and AppTheme setting -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style x:Key="MinimalChartStyle" TargetType="chart:ChartBase">
<Setter Property="Width" Value="500"/>
<Setter Property="Height" Value="500"/>
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
ViewModel.cs
public class ReqTotalViewModel:ObservableObject
{
class TestPageViewModel
{
public ObservableCollection<TestClass> Errors { get; private set; }
public TestPageViewModel()
{
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;
}
}
}
public class TestClass
{
public string Category { get; set; }
public int Number { get; set; }
}
}
MainWindow.xaml
<Controls:MetroWindow x:Class="ReqTotalWPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="clr-namespace:ReqTotalWPF"
Title="ReqTotals" Height="800" Width="963"
xmlns:xctk ="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:xcdg ="http://schemas.xceed.com/wpf/xaml/datagrid"
xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:metroChart="clr-namespace:De.TorstenMandelkow.MetroChart;assembly=De.TorstenMandelkow.MetroChart"
WindowStartupLocation="CenterScreen"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro">
<Grid Background="#2F2C38"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="25"/>
<RowDefinition Height="30*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="1">
<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>
</StackPanel>
</Grid>
MainWindow.xaml.cs
public partial class MainWindow : MetroWindow
{
public MainWindow()
{
InitializeComponent();
this.DataContext = new ReqTotalViewModel();
}
}
Any help would be much appreciated. Thank you!