1

I have converted the following C# code to VB.NET code via http://converter.telerik.com/

public static MessageBoxResult Show(string caption, string text, MessageBoxButton button, MessageBoxImage image)
{
    _messageBox = new WpfMessageBox { Label1 = { Content = caption }, Label2 = { Content = text } };
    return _result;
}

This is the converted VB.NET code.

Public Shared Function Show(caption As String, text As String, button As MessageBoxButton, image As MessageBoxImage) As MessageBoxResult
    _messageBox = New WpfMessageBox() With { _
        Key .Label1 = {Key .Content = caption}, _
        Key .Label2 = {Key .Content = text} _
    }
    Return _result
End Function

Here is the error:

Error

Ry-
  • 218,210
  • 55
  • 464
  • 476
  • This definitely invalid syntax in vb.net. You need to read about how to initialize WpfMessageBox with inline initialization. Or create instance of WpfMessageBox first and the set its properties. – Chetan Sep 18 '17 at 02:49

2 Answers2

2

This is a bug in the converter.

The Key prefix is used for anonymous types to affect equality; it is not legal for typed object initializers.

Remove that.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
1

The converter seems to think there’s an anonymous type involved here, but there isn’t. Remove Key.

Public Shared Function Show(caption As String, text As String, button As MessageBoxButton, image As MessageBoxImage) As MessageBoxResult
    _messageBox = New WpfMessageBox()
    _messageBox.Label1.Content = caption
    _messageBox.Label2.Content = text
    Return _result
End Function
Ry-
  • 218,210
  • 55
  • 464
  • 476
  • @MarkoMarkowitz: Answer updated to add `New Label()`, assuming `System.Windows.Controls` is imported. – Ry- Sep 18 '17 at 02:55
  • @MarkoMarkowitz: Sorry, forgot a keyword – it’s `New Label() With`, same as when creating the `WpfMessageBox`. – Ry- Sep 18 '17 at 03:00