is a framework (first introduced in .NET3.0) for building rich dynamic
GUI. Any C# script utilizing the
WPF classes can be executed by CS-Script as any other scripts. It is
possible because from the CLR point of view WPF classes are just
ordinary CLR classes.
That is it WPF
is nothing else but a collection of CLR classes.
WPF is directly related to XAML - another part of .NET3.0+.
Application Markup Language
a language for describing GUI layout and it's relationships with the
business objects. XAML primarily used in conjunction with WPF. Usually
it is used in a compiled form for initialization GUI layout at
runtime and as
such it does require it's own compiler.
important to note that XAML has nothing to do with CLR. This is the
reason why scripts which are utilizing XAML has to be handled by the
script engine in a special way.
WPF script which are not using XAML do not require any special
treatment and can be executed normally.
Starting from version 1.9.0 CS-Script includes special edition of the
C# compiler capable of processing XMAL files. The following code
sample demonstrates how WPF script can use XAML:
public partial class MainWindow : System.Windows.Window
void OnClick(object sender, RoutedEventArgs e)
public static void Main()
MainWindow wnd = new MainWindow();
Title="Hello World Application" Height="117" Width="280">
<Button Margin="108,27,109,34" Name="button1" Click="OnClick" >Say Hello</Button>
The code above is a
WPF multi-file "Hello World" script (Hello.cs + Hello.xaml
from CS-Script samples library (Script Library). Xaml file can be
included in the primary script as any other secondary script file: with
(in short form //css_imp
Unfortunately MS did not provide XAML compiler as a stand-alone
application. Instead MS has merged XAML compiler with MSBuild.exe
this form it is used by CS-Script custom compiler CSSCodeProvider.dll
approach is inconsistent with the way how C# code is usually
by CS-Script. And that is why implementation of the XAML support may
change in future depending on MS decision to
version of XAML compiler.
You may also notice that WPF scripts and executables produces from the
scripts sometimes demonstrates slight startup-delay. This is a .NET
bag, which was already reported to MS
Silverlight is a subset of WPF and as such does not require any special
technique to be executed as a script: you just need to reference
appropriate assemblies and include code-behind and XAML files
(this can change in the future). However CS-Script offers an
interesting technique for viewing Silverlight content without a
browser: Silverlight Player script (<cs-script>\Lib\silverlight.cs).
Execute the following command in command to playback XAP file (e.g. myApp.xap
cscs silverlight myApp.xap
Silverlight Player is a viewer for XAP (compressed Silverlight
content) files. Silverlight Player is capable not only rendering
Silverlight content but also generating self-sufficient executable from
Thus you can convert XAP file into WinForm executable which can be
executed on any Windows PC having Silverlight runtime installed. It
does not require any other files to be distributed or even temporary
created on target PC at runtime as it hosts it's own built-in
Web server, IE Web browser and contains XAP file as embedded
Execute the following command in command prompt to convert XAP file into self-sufficient executable (e.g. myApp.xap
cscs silverlight /exe myApp.xap
using Silverlight Player by right clicking XAP files in
Windows Explorer the "View" and "Convert to EXE" shell extensions have
been made available. They can be installed by executing corresponding
batch files from <cs-script>\Samples\Silverlight directory.
Silverlight Player script was inspired by Tamir Khason effort described here: http://blogs.microsoft.co.il/blogs/tamir/archive/2008/05/02/stand-alone-multiplatform-silverlight-application.aspx
Silverlight content sample (BookPages.xap) is taken from SOTC: programming and
development tutorial blog