2012-03-20 54 views
1

我正試圖在互聯網上找到一些相機相關教程。問題是,大多數教程都是用C#完成的,而我需要它在VB.NET。我曾嘗試使用在線轉換器轉換它,但它並不總是識別所有的語法,因此我得到錯誤。如何將其轉換爲Visual Basic?如何將此方法從C#轉換爲VB.NET

Loaded += (_, __) => 
    { 
     Microsoft.Phone.Shell.PhoneApplicationService.Current.ApplicationIdleDetectionMode = 
      Microsoft.Phone.Shell.IdleDetectionMode.Disabled; 

     cam = new VideoCamera(); 
     cam.Initialized += (___, ____) => 
      { 
       cam.LampEnabled = true; 
       cam.StartRecording(); 
      }; 
     vCam.SetSource(cam); 

     new Thread(() => 
      { 
       try 
       { 
        var isf = IsolatedStorageFile.GetUserStoreForApplication(); 

        var files = isf.GetFileNames(); 
        foreach (var file in files) 
        { 
         Debug.WriteLine("Deleting... " + file); 
         isf.DeleteFile(file); 
        } 
       } 
       catch (Exception ex) 
       { 
        Debug.WriteLine("Error cleaning up isolated storage: " + ex); 
       } 
      }).Start(); 
    }; 

這是我從轉換器得到的代碼:

Loaded += Function(_, __) 
Microsoft.Phone.Shell.PhoneApplicationService.Current.ApplicationIdleDetectionMode = _ 
    Microsoft.Phone.Shell.IdleDetectionMode.Disabled 

cam = New VideoCamera() 
cam.Initialized += Function(___, ____) 
cam.LampEnabled = True 
cam.StartRecording() 

End Function 

vCam.SetSource(cam) 

New Thread(Function() 
Try 
    Dim isf = IsolatedStorageFile.GetUserStoreForApplication() 
    Dim files = isf.GetFileNames() 
    For Each file As var In files 
     Debug.WriteLine("Deleting... " & Convert.ToString(file)) 
     isf.DeleteFile(file) 
    Next 
Catch ex As Exception 
    Debug.WriteLine("Error cleaning up isolated storage: " & ex) 
End Try 

End Function).Start() 

End Function 
+0

我使用了一個轉換器,它的字面意思是給我錯誤無處不在 – Matt9Atkins 2012-03-20 00:31:05

+0

我建議發佈轉換器做了什麼,所以人們可以幫助縮小錯誤。 – 2012-03-20 00:31:58

+0

我在轉換器代碼中添加了 – Matt9Atkins 2012-03-20 00:34:10

回答

0

使用Roslny。轉換器在00分55秒出現。

PS:下劃線對於變量名是一個壞主意。

+0

下劃線用於命名從不被引用的函數參數,但他沒有編寫代碼,所以他可能沒有給它們命名。 – Gabe 2012-03-20 01:20:32

-1

使用下面的(我用Telerik Converter):

Loaded += Function(_, __) Do 
    Microsoft.Phone.Shell.PhoneApplicationService.Current.ApplicationIdleDetectionMode = Microsoft.Phone.Shell.IdleDetectionMode.Disabled 

    cam = New VideoCamera() 
    cam.Initialized += Function(___, ____) Do 
     cam.LampEnabled = True 
     cam.StartRecording() 
    End Function 
    vCam.SetSource(cam) 


    New Thread(Function() Do 
     Try 
      Dim isf = IsolatedStorageFile.GetUserStoreForApplication() 
      Dim files = isf.GetFileNames() 
      For Each file As var In files 
       Debug.WriteLine("Deleting... " + file) 
       isf.DeleteFile(file) 
      Next 
     Catch ex As Exception 
      Debug.WriteLine("Error cleaning up isolated storage: " + ex) 
     End Try 
    End Function).Start() 
End Function 

我希望這有助於:)

+0

Visual Studio中的各種錯誤:( – Matt9Atkins 2012-03-20 01:37:07

+1

我不認爲+ =在添加事件處理程序時起作用,您應該使用AddHandler語句。 – 2012-03-20 13:36:31

0

你的轉換器似乎不知道如何處理+ =運算符或下劃線做VB。他們正在對編譯器造成嚴重破壞。

變化

Loaded += Function(_, __) 
    Microsoft.Phone.Shell.PhoneApplicationService.Current.ApplicationIdleDetectionMode = Microsoft.Phone.Shell.IdleDetectionMode.Disabled 

AddHandler Loaded , Function(x as Object, y as Object) 
    Microsoft.Phone.Shell.PhoneApplicationService.Current.ApplicationIdleDetectionMode = _ 
     Microsoft.Phone.Shell.IdleDetectionMode.Disabled 

,改變

cam.Initialized += Function(___, ____) 

AddHandler cam.Initialized, Function(xx as Object, yy as Object) 

請注意,您可能需要更改事件處理程序中的Object簽名以匹配實際的事件簽名,但其他內容一眼就能看到。