Porting the Application
I started with the standard project template "F# Empty Windows App (WPF)". Following the tutorial, the first step is to fill the main window XAML file with the layout of the application. Using the XAML type provider of the FSharpx package which is already included to the project references by the project template, the GUI binding declarations in the XAML configuration are available in the F# source file. The only issue I ran into was the failing access to the TextBox widget which I had to bind manually:
The other aspect to deal with relates to the treatment of the wire model. The model is built up by using the 3DTools library (published under the Microsoft Limited Permissive License (Ms-LPL)). This model does not comply to the necessary type hierarchy as expected by WPF. Hence, a workaround has to be applied:
In order to achieve this, the Viewport3D element of the main window needs to be available as a reference within the MainWindow module:
The application demonstrates the functionality to toggle between graphic objects (triangle, cube and mesh). Each of these objects comes with its own additions to the viewport container. In order to restore the ViewportObject to the initial state as declared in the XAML file, these added elements have to be removed. The baseline of the initial is the preconfigured the camera:
The strategy of the demo application is to deleted all elements which were added after the initial state:
The solution, while certainly not idiomatic, shows an interesting difference between F# and C#, because C# allows to iteratively change a mutable collection which is not possible in the same fashion in F#:
At this point, the release version of the 3DTools library contains an error which leads to dangling null pointer: the viewport descendants register internally a handler which becomes void after removal of the corresponding descendant. A later patch fixes this issue. I retrieved the patched version from Mike Hodnick´s github repository and added it to my own project.
The code of this port is on Github.
© Apache 2.0 license, the same as F#, where applicable.