2014-09-20 1 views
-2

필자는 CodePlex에서 현대 UI (Metro) Charts를 발견했으며,이 프로젝트를 완료하기 위해 찾고있는 것을 정확하게 찾았습니다. 그들은 일반적으로 매우 효과적이지만이 코드가 작동하려면 얻이 수없는 것 - 나는 C 번호를 작성하지 않기 때문에C#에서 VB.NET으로 변환 - 어디에서 잘못 될까요?

https://modernuicharts.codeplex.com/documentation

그러나,이 같은 상황에서 온라인 컨버터에 의존하고 있습니다. 누구든지 필요한 수정안의 방향으로 나를 가리킬 수 있습니까? 많은 감사!

C# 코드 :

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 번역 :

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 

오류 :

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 
+2

적절한 공간이 필요합니다. 그들에 대해서는 당신이 이해하지 못하니? –

+0

내 .. VB에서 C#을 다시 작성하려고합니다. 그래서 나는 VB # ** ** ** C#보다 더 잘 알고 있다고 가정합니다. 그렇다면 ** 컴파일러 ** 오류 메시지를 이해할 때 어떤 문제가 있습니까? 그것들은 100 % 순 VB 및 .Net 문제와 관련이 있습니다. 그들은 명확하고 VB를 안다면 꽤 분명해야합니다. 정확히 당신은 그 (것)들에서 이해하지 못합니까? – quetzalcoatl

답변

3
  • 가 모두 제거같은 anonymous-types되지 구체적인 유형에 속하는 .
  • Key으로

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 

두 익명 형식이 동일한 경우 결정하는 데 사용하고있는 사용되는 propertis 지정할 수 있습니다 (VS는 오류를 올려 놓으면 있음을 알려줍니다) Imports System.Collections.ObjectModel 추가 컴파일러 생성 해시 코드 알고리즘 C#에서는 모든 속성이 자동으로 사용되므로 변경할 수 없습니다.

+0

죄송 합니다만, 나는 downvotes를 기대하고 있었지만 이것은 내가 정확히 무엇을 찾고 있었는지 - 감사합니다. Object Model을 직접 가져올 수 있었지만 키를 이해하지 못했습니다. 감사 –

1

Tim Schmelter가 첫 번째 문제를 해결했습니다. 마지막 오류에 대한

당신은 그 오류 메시지는 매우 설명 것

Imports System.Collections.ObjectModel