Reputation: 2153
I'm trying to add https://modernuicharts.codeplex.com/ WPF project into my solution. I extracted the projects that was needed for wpf
Library - De.TorstenMandelkow.MetroChart.WPF
TestApplications - TestApplication.Shared
- TestApplicationWPF
De.TorstenMandelkow.MetroChart
I right clicked my current solutions and I went to Add -> Add Existing project and added the above projects.
When I set TestAplicationWPF as start up Project, the Project runs completely fine.
My goal is to have a button which will display Modern UI Charts Interface in my other project called "WPF".
WPF - ViewModel
//Button Code
public MainWindow ShowModernUI()
{
return new TestApplicationWPF.MainWindow();
}
It returns this error A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll
I checked the inner exception and it gave me "Cannot find resource named 'PageContent'
which corresponds to TestAplicationWPF.MainWindow.xaml code
TestAplicationWPF.MainWindow.xaml
<ContentControl Content="{Binding}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" ContentTemplate="{StaticResource PageContent}" />
Page Content is from a resource Dictionary within TestAplicationWPF.
My attempt to fix the problem was to create a copy of the resource dictionary within my "WPF" project and it removed the error but nothing shows. May I ask how do I display the MainWindow from TestApplicationWPF
Upvotes: 1
Views: 520
Reputation: 16662
Here's how to fix it:
There are few issues with the library, there used to be a Nuget package but it has been unlisted so I'll show you how to compile and reference the library in your WPF app.
SourceAndTestApplications.zip
by clicking Download on the rightMetroChart
folder somewhere and open the MetroChart.sln
inside itIf you are using VS2013 the following screen will appear:
Nothing to worry about, just press OK and close the Migration Report it opened in IE
Again, if you are under Windoww 8.1, the following will appear:
Just press OK.
Now there's something you need to do for the compilation to succeed:
De.TorstenMandelkow.MetroChart
Building
De.TorstenMandelkow.MetroChart.WPF
project and build itMetroChart\De.TorstenMandelkow.MetroChart.WPF\bin\Release
Reference the project
De.TorstenMandelkow.MetroChart.dll
XAML :
<Window x:Class="WpfApplication3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:metroChart="clr-namespace:De.TorstenMandelkow.MetroChart;assembly=De.TorstenMandelkow.MetroChart"
xmlns:wpfApplication3="clr-namespace:WpfApplication3"
Title="MainWindow"
Width="525"
Height="350">
<Window.Resources>
<wpfApplication3:MyObjectCollection x:Key="MyObjectCollection">
<wpfApplication3:MyObject Category="Category1" Value="100" />
<wpfApplication3:MyObject Category="Category2" Value="200" />
<wpfApplication3:MyObject Category="Category3" Value="300" />
</wpfApplication3:MyObjectCollection>
<metroChart:ResourceDictionaryCollection x:Key="CustomColors">
<ResourceDictionary>
<SolidColorBrush x:Key="Brush1" Color="#FF5B9BD5" />
</ResourceDictionary>
<ResourceDictionary>
<SolidColorBrush x:Key="Brush2" Color="#FFED7D31" />
</ResourceDictionary>
<ResourceDictionary>
<SolidColorBrush x:Key="Brush3" Color="#FFA5A5A5" />
</ResourceDictionary>
<ResourceDictionary>
<SolidColorBrush x:Key="Brush4" Color="#FFFFC000" />
</ResourceDictionary>
<!-- add more values with a different key -->
</metroChart:ResourceDictionaryCollection>
</Window.Resources>
<Grid>
<metroChart:PieChart Palette="{StaticResource CustomColors}"
>
<metroChart:PieChart.Series>
<metroChart:ChartSeries DisplayMember="Category"
ItemsSource="{StaticResource MyObjectCollection}"
ValueMember="Value" />
</metroChart:PieChart.Series>
</metroChart:PieChart>
</Grid>
</Window>
Code-behind:
using System.Collections.ObjectModel;
using System.Windows;
namespace WpfApplication3
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow() {
InitializeComponent();
}
}
internal class MyObject
{
public string Category { get; set; }
public int Value { get; set; }
}
internal class MyObjectCollection : ObservableCollection<MyObject>
{
}
}
Result
See https://modernuicharts.codeplex.com/documentation for help.
Upvotes: 1