Introduction
In this article, I can illustrate what is Fireball.XmlGui and give a brief introduction to it. The library is under development and any suggestions and bug feedback are very much appreciated. If you find a bug please register here and send us the issues. Fireball.XmlGui is licensed under LGPL and this is very useful for programmers who need to use the library for commercial applications because LGPL doesn't force you to distribute your source code, you only need to distribute or link to my site for Fireball.XmlGui source code. For news about this library, go to my home page and get the latest binary from there.
Background
Fireball.XmlGui was developed for adding to plug-in based applications the support for creating dynamic plug-ins with a simple XML file. The syntax is very like XAML and it is also possible to use the code-behind! You only need to specify on the root of the document the attribute CodeBehind
with the filename of the C# source file. The library is not limited to System.Windows.Forms
GUI creation. You can also use it for dynamically creating any other type of classes, for adding classes as subnodes on the XML, like the Controls
tag on this example. You need only the collection and inherit from the System.Collections.IList
.
Using the code
See the next XML sample code:
="1.0" ="utf-8"
<XFGDocument Name="Sample XmlGui"
NameSpaces="System.Drawing,System.Windows.Forms,
customNamespace,Fireball.XmlGui.Graphics"
CodeBehind="formsample.fxg.cs">
<References>
<Assembly Name="System.dll" />
<Assembly Name="System.Drawing.dll" />
<Assembly Name="System.Windows.Forms.dll" />
</References>
<MyForm Name="Prova" Height="300" Width="400" Text="Hello World!">
<Controls>
<ToolStrip Name="ToolStrip1">
</ToolStrip>
<MenuStrip Name="MenuStrip1">
<Items>
<ToolStripMenuItem Text="File" >
<DropDownItems>
<ToolStripMenuItem Text="New" Click="MyForm.OpenClick"/>
<ToolStripMenuItem Text="Open" Click="MyForm.OpenClick"/>
</DropDownItems>
</ToolStripMenuItem>
</Items>
</MenuStrip>
<Panel Dock="Fill" BackColor="Color.Red">
<Controls>
<WebBrowser Name="browser1" Dock="Fill" />
</Controls>
</Panel>
<StatusStrip />
</Controls>
</MyForm>
</XFGDocument>
The root element is XFGDocument
. On this tag you need to set its name and the NameSpaces
attribute to all namespaces you need to use from XML each separated by a , (comma). You can also specify the code-behind file with the attribute CodeBehind
. In this example, the first child tag of the document needs to be a form. In this example, I use the class declared on the code-behind file. MyForm
is a class that inherits from System.Windows.Forms.Form
. Next, the source code of the code-behind file:
using System;
using System.Drawing;
using System.Windows.Forms;
namespace customNamespace
{
public class MyForm : Form
{
static MyForm MyFormIstance;
public MyForm()
{
MyFormIstance = this;
}
public static void OpenClick(object sender,EventArgs e)
{
WebBrowser br =
(WebBrowser)MyFormIstance.Controls.Find("browser1", true)[0];
br.Navigate("http://www.dotnetfireball.org");
}
}
}
The source code is very short and simple, and you don't need to be a guru for creating a GUI with this library ;). On the XML code, if you need to set a property, you can do it as an attribute. For the moment, that is all. If you have any questions about the library, don't hesitate to contact me. I plan to write more about this library in future. At the moment, my time is dedicated to the development of the library, and other works ;)
Note: for running the sample, go on the sample bin/debug directory and execute the run.bat file.