Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

VB.NET, NeoLua and External XAML Implementation

0.00/5 (No votes)
17 Nov 2015 1  
Example of loading external scripting and external XAML with VB.NET and NeoLua

Introduction

This is an example of combining VB.NET, NeoLua as external scripting and external XAML. It solve these problems:

  • Loading XAML externally
  • Assigning loaded XAML's DataContext from lua
  • Binding loaded XAML's Events to function in lua
  • Extend the content of a Window

Background

At the time of this writing, I was just starting to use .NET and WPF. Migrating from the web world, I was forced to leave all the dynamicity of the web world behind. At the same time, I was working on a project that took several minutes for each build to complete. It was from there I came up with the idea of combining VB.NET, NeoLua and XamlLoader in order to generate content dynamically.

The idea is actually to create an extendable VB.NET more than scripting the entire system externally although this example does exactly that.

Why Not IronPython or Awesomium or ...?

For IronPython, I chose NeoLua because the implementation is super easy and from what I heard, IronPython requires you to have the Python's Library while NeoLua, you just need the NeoLua libraries. (I might be wrong?)

For Awesomium, the requirement was to use XAML and not HTML.

Drawbacks

  • Lua and XAML have no intellisense.
  • NeoLua Exception is not 100% accurate. (ex, const error will show line and column of [0, 0])
  • Not for strong-typed dependant environment because of the dynamicity.

Using the Code

This code was meant for you to study on it. To give you some hints:

  • The entire NeoLua extension was put under a folder called Engine
  • Adding event from lua requires a help from a function called LuaAddEvent check LuaWindow
  • To make a Window Scriptable, you must inherit from LuaWindow check MainWindow.xaml
  • XAML Content's Root for LuaWindow is Page while for LuaContent is UserControl check Main.xaml and Content1.xaml
  • LuaWindow and LuaContent both load from Scripts and Contents of the same name. (ex: Main.xaml, Main.lua)
  • Both Scripts and Contents folder was copied from the solution upon run
  • External XAML cannot have an x:Class
  • At the time of writing, NeoLua const for generic does not work properly (other than List) Fixed
  • Event uses a Dictionary with Key<Parent, Element, LuaResult> and Value<Delegate>
  • Event's Key.Parent is needed in order to prevent clearing events incorrectly.

History

  • Revision 2 - NeoLua const problem is now fixed.
  • Revision 1 - First release

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here