This post should be relatively short and code free but it’s not without some usefulness…hopefully! If you are like me and hate writing the same old code over and over again, visual studio has the ability to create Custom Templates. This is great if you have some boiler plate code you know you will use for all your projects, in this case creating a VS Template for View Extensions in Dynamo with WPF and MVVM pattern all set up and ready to rock n’ roll.

What’s in the box…

The Template has the following basic project setup…

  • Main Class for entry point for ViewExtension implementing the Dynamo IViewExtension interface and Menu’s hooked up to ViewExtension ViewModel.
  • The ViewExtension_ViewExtensionDefinition.xml already populated.
  • A ViewExtension folder with Model, View, ViewModel subfolder and classes/xaml with basic MVVM hookups and data binding.
  • Standard RelayCommand class for buttons and commands etc.
  • Nuget references to Dynamo and Newtonsoft Nuget Packages. You need to reload these in the Nuget Package Manager and rebuild, or you could remove these altogether and load directly from the Dynamo Core directory. Just make sure you set Copy Local to False on your references! I always forget to do this!

This should run OOTB and give you a very basic UI just so you can see how it all works, but it is really meant to be a starting point for you to hack to pieces and create your own awesome View Extension.

Install instructions…

  1. To use this, you first need to download the Template from here.
  2. Once you have downloaded the Template, you need make sure you have Unblocked the .zip (right click > Properties > Unblock Checkbox at the bottom.
  3. Then all you need to do is copy it to the Visual Studio Template directory which should be C:\Users\<Your Profile>\Documents\Visual Studio 2017\Templates\ProjectTemplates

That should be about it…now when you open Visual Studio and create a new Project you should see this in the Visual C# section…

and after you have created a project, you will see it in your Recent Project Templates like this…

If you change the class name for the MyViewExtension.cs entry point, then make sure to change the .xml in the MyViewExtension_ViewExtensionDefinition.xml

<ViewExtensionDefinition&gt;
  <AssemblyPath&gt;..\ExampleVE.dll</AssemblyPath&gt;
  <TypeName&gt;ExampleVE.YOUR_NEW_CLASS_NAME</TypeName&gt;
</ViewExtensionDefinition&gt;

And rename MyViewExtension_ViewExtensionDefinition.xml to YOUR_NEW_CLASS_NAME _ViewExtensionDefinition.xml

There are little instructions in the Template which should prompt you to change this and that, nice and easy!

Hope you find this useful! Happy coding and thanks for reading. 😉

Advertisements