2012-04-16 48 views
0

我有下面的Windows Phone 7应用程序的示例代码,我试图将它转换为VB.Net作为起点。这样的分配:如何从C#中的匿名事件处理程序转换为VB.Net

Loaded += (_, __) => { anonymousMethodBody();} 

是失败当我使用C#-to-VB转换工具转换。这些应该如何翻译?

public MainPage() 
{ 
    InitializeComponent(); 

    Loaded += (_, __) => 
     { 
      PhoneApplicationService.Current.ApplicationIdleDetectionMode = 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(); 
     }; 
} 
+0

你得到哪些错误? – 2012-04-16 16:43:42

+0

有关类似于+ =(___,____)=> – Matt9Atkins 2012-04-16 16:45:40

+3

的方法的错误您的lambda命名约定会使我的眼睛流血。 – abatishchev 2012-04-16 17:04:49

回答

3

Loaded事件处理程序在你张贴使用lambda表达式C#代码定义。我想大多数VB.NET-C#转换器不能很好地处理这些问题,因为它们相对较新。试试这个:

AddHandler Loaded, Sub() 'Pass the Loaded event parameters, I cannot see them in your code 
        'The code inside the big block 
        End Sub 

你不需要拨打RemoveHandler(阅读下面的评论)。

+0

我在哪里添加代码以删除处理程序? – Matt9Atkins 2012-04-16 17:15:58

+0

您不会删除事件处理程序侦听器。 – 2012-04-16 17:30:18

+0

@Tetsujin no Oni:不应该在'Dispose'中删除它吗? – 2012-04-16 18:46:44

相关问题