I was looking for an overview on how to create a WYSIWYG layout editor for a project I’m working on. Found something ideal, with the remaining small task of converting it into vb.net…
The setup’s complicated. I’m creating a winforms project, but I need advanced graphics capabilities that I can only get through WPF (via integrating WPF custom controls into my winforms app). Now, I’m only just getting started on WPF so the task of converting a c# wpf project into a vb one was quite difficult. VB.net version download:
The original article is here:
https://www.codeproject.com/Articles/22952/WPF-Diagram-Designer-Part-1
I’d urge you to download it and have a look at the different project stages. I used this code as the basis for my conversion. Here’s some notes on the conversion:
There was a really annoying exception preventing compile, giving me some kind of ‘can’t find in namespace’ error. Appears to be an annoying intermittent thing with VisualStudio:
https://stackoverflow.com/questions/15051121/the-name-does-not-exist-in-the-namespace-clr-namespace
I think the thing that did it for me was changing the Target CPU in the Project Compile menu. Then I got an error saying CPU mismatch and when changed back, the error was fixed.
It could have also been changing the namespace in the top level element of the form:
|
1 |
xmlns:s="clr-namespace:DiagramDesigner.DiagramDesigner" |
There were a couple of challenging bits to the conversion. Firstly, most online code converters missed the AddHandler conversion. For example:
|
1 2 3 4 5 |
public MoveThumb() { DragStarted += new DragStartedEventHandler(this.MoveThumb_DragStarted); DragDelta += new DragDeltaEventHandler(this.MoveThumb_DragDelta); } |
converted into:
|
1 2 3 4 |
Public Sub New() DragStarted += New DragStartedEventHandler(Me.MoveThumb_DragStarted) DragDelta += New DragDeltaEventHandler(Me.MoveThumb_DragDelta) End Sub |
The resolved code being:
|
1 2 3 4 |
Public Sub New() AddHandler DragStarted, New DragStartedEventHandler(AddressOf Me.MoveThumb_DragStarted) AddHandler DragDelta, New DragDeltaEventHandler(AddressOf Me.MoveThumb_DragDelta) End Sub |
Also, one particularly tricky conversion:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
public class DoubleFormatConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { double d = (double)value; return Math.Round(d); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return null; } } |
converted into:
|
1 2 3 4 5 6 7 8 9 10 11 12 |
Public Class DoubleFormatConverter Inherits IValueConverter Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As CultureInfo) As Object Dim d As Double = CDbl(value) Return Math.Round(d) End Function Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As CultureInfo) As Object Return Nothing End Function End Class |
which was way off (IValueConverter being the culprit). Final working code:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Public Class DoubleFormatConverter Implements IValueConverter Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As CultureInfo) As Object Implements IValueConverter.Convert Dim d As Double = CDbl(value) Return Math.Round(d) End Function Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As CultureInfo) As Object Implements IValueConverter.ConvertBack Return Nothing End Function End Class |
For completeness, another thing I had to do was Must import reference UIAutomationProvider.dll from:
|
1 |
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\UIAutomationProvider.dll |
Enjoy!

Leave a Reply