Master
Master

Reputation: 2153

Adding an existing project to Solution Trouble shooting

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

Answers (1)

aybe
aybe

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.

  • download the file SourceAndTestApplications.zip by clicking Download on the right
  • extract the MetroChart folder somewhere and open the MetroChart.sln inside it

If you are using VS2013 the following screen will appear:

enter image description here

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:

enter image description here

Just press OK.

Now there's something you need to do for the compilation to succeed:

  1. open Configuration Manager
  2. choose Release Build
  3. untick Build for De.TorstenMandelkow.MetroChart

enter image description here

Building

  • right-click De.TorstenMandelkow.MetroChart.WPF project and build it
  • when built, find the DLL in MetroChart\De.TorstenMandelkow.MetroChart.WPF\bin\Release

Reference the project

  • create a new WPF project
  • add a reference to 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

enter image description here

See https://modernuicharts.codeplex.com/documentation for help.

Upvotes: 1

Related Questions