-2

I have recently discovered the Modern UI (Metro) Charts on CodePlex which looks to be truly excellent, and exactly what I'm looking for to complete this project.

https://modernuicharts.codeplex.com/documentation

As I don't write C#, however, I rely on online converters in situations like this - they are normally very effective, but I can't seem to get this code to work. Can anyone point me in the direction of the necessary amendments? Many Thanks!

C# Code:

namespace TestApplication
{
    // bind this view model to your page or window (DataContext)
    public 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;                
            }
        }
    }

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

        public int Number  { get; set; }        
    }
}

VB.NET Translation:

Public Class TestPageViewModel
    Public Property Errors() As ObservableCollection(Of TestClass)
        Get
            Return m_Errors
        End Get
        Private Set
            m_Errors = Value
        End Set
    End Property
    Private m_Errors As ObservableCollection(Of TestClass)

    Public Sub New()
        Errors = New ObservableCollection(Of TestClass)()
        Errors.Add(New TestClass() With { _
            Key .Category = "Globalization", _
            Key .Number = 75 _
        })
        Errors.Add(New TestClass() With { _
            Key .Category = "Features", _
            Key .Number = 2 _
        })
        Errors.Add(New TestClass() With { _
            Key .Category = "ContentTypes", _
            Key .Number = 12 _
        })
        Errors.Add(New TestClass() With { _
            Key .Category = "Correctness", _
            Key .Number = 83 _
        })
        Errors.Add(New TestClass() With { _
            Key .Category = "Best Practices", _
            Key .Number = 29 _
        })
    End Sub

    Private m_selectedItem As Object = Nothing
    Public Property SelectedItem() As Object
        Get
            Return m_selectedItem
        End Get
        Set
            ' selected item has changed
            m_selectedItem = value
        End Set
    End Property
End Class

Errors:

Error   2   Name of field or property being initialized in an object initializer must start with '.'.   C:\Users\Major\documents\visual studio 2013\Projects\WpfApplication3\WpfApplication3\pModernChart.xaml.vb   17  4   WpfApplication3

Warning 1   'Public Sub New()' in designer-generated type 'WpfApplication3.pModernChart' should call InitializeComponent method.    C:\Users\Major\documents\visual studio 2013\Projects\WpfApplication3\WpfApplication3\pModernChart.xaml.vb   14  16  WpfApplication3

Error   1   Type 'ObservableCollection' is not defined. C:\Users\Major\documents\visual studio 2013\Projects\WpfApplication3\WpfApplication3\pModernChart.xaml.vb   2   33  WpfApplication3
Jiminy Cricket
  • 1,377
  • 2
  • 15
  • 24
  • 2
    Those error messages seem very descriptive. What about them don't you understand? – Ed S. Sep 20 '14 at 18:55
  • My.. you want to rewrite C# into VB - ok. So I assume, you know VB **better** than C#, right? So what problem do you have in understanding those **compiler** error messages? They are 100% related to pure VB and .Net matters. They are clear, and if you know VB, they should be quite obvious. What exactly do you not understand in them? – quetzalcoatl Sep 20 '14 at 18:58

2 Answers2

3
  • Remove all the Key which belong to anonymous-types not concrete types like TestClass.
  • add Imports System.Collections.ObjectModel (VS tells you that if you hover the error)

Public Class TestPageViewModel
    Public Property Errors() As ObservableCollection(Of TestClass)
        Get
            Return m_Errors
        End Get
        Private Set(value As ObservableCollection(Of TestClass))
            m_Errors = value
        End Set
    End Property
    Private m_Errors As ObservableCollection(Of TestClass)

    Public Sub New()
        Errors = New ObservableCollection(Of TestClass)()
        Errors.Add(New TestClass() With {
             .Category = "Globalization",
             .Number = 75
        })
        Errors.Add(New TestClass() With {
            .Category = "Features",
            .Number = 2
        })
        Errors.Add(New TestClass() With {
             .Category = "ContentTypes",
             .Number = 12
        })
        Errors.Add(New TestClass() With {
         .Category = "Correctness",
             .Number = 83
        })
        Errors.Add(New TestClass() With {
             .Category = "Best Practices",
             .Number = 29
        })
    End Sub

    Private m_selectedItem As Object = Nothing
    Public Property SelectedItem() As Object
        Get
            Return m_selectedItem
        End Get
        Set(value As Object)
            ' selected item has changed '
            m_selectedItem = value
        End Set
    End Property
End Class

With Key you can specify which propertis are used to determine if two anonymous types are equal and which are used in the compiler-generated hash code algorithm. In C# all properties are used automatically and you cannot change it.

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
  • Apologies, I was expecting downvotes, but this has given me exactly what I was looking for - thanks a lot. I managed to Import the Object Model myself, but I didn't understand the Key. Thanks – Jiminy Cricket Sep 20 '14 at 19:16
1

Tim Schmelter solved your first problem.

For the last error you need the proper namespace

Imports System.Collections.ObjectModel
Kammersgaard
  • 74
  • 1
  • 2