CodeConverter icon indicating copy to clipboard operation
CodeConverter copied to clipboard

VB -> C#: Basic WPF Transformations

Open HeinziAT opened this issue 1 year ago • 0 comments

I just converted a WPF project from VB.NET to C#. There were a few basic transformations that had to be done manually. I want to describe them in this issue to (a) aid other people doing the same and (b) provide a TODO list in case anyone wants to add these transformations to CodeConverter.

These "issues" can be reproduced by creating a vanilla VB WPF (.NET 7) project with the Visual Studio default template, adding a "Hello World" text block to the main window and converting it to C# with the CodeConverter extension (I used 9.1.3.0).

  • You need to add the default namespace to all x:Class attributes in the root element of your XAML files. The VB compiler adds the default namespace automatically, but the C# compiler doesn't.
  • If no Sub Main() exists, you need to rename Application.xaml(.cs) to App.xaml(.cs). Apparently, C# only auto-generates a void Main for an App.xaml, not for an Application.xaml.
  • If your XAML files have non-default visibility (e.g. x:ClassModifier="Friend"), this value needs to be converted to the corresponding C# value (in this case x:ClassModifier="internal").

HeinziAT avatar Mar 17 '23 14:03 HeinziAT