Programming‎ > ‎WPF‎ > ‎

Scripts in XAML

This is a nice idea of exteding XAML with script language:

This is for Silverlight. I'm copying it here, because I feel that someday I will want to do the same in WPF and I don't want to loose this example as reference. The implementation is suprisingly easy. Assuming that you have scripting language already (and that should be no problem at these times).

The XAML code can like this:

    <scriptingRuntime:ScriptContext x:Key="defaultContext"/>

<Button x:Name="button1" Content="Click Me" Width="100">
    <scriptingToolkit:CodeBlock ExecutionContext="{StaticResource defaultContext}">
            MessageBox.Show("Button was clicked!");
                      textBox = Form.FindName("textBox");
                      textBox.Text = "Dynamically modified text";


Of course it should be used wisely and it is not recommended for novice WPF programmers.

Another example: "Using IronPython in WPF to Evaluate Expressions" by Sacha Barber.

Marek Ogarek,
Aug 7, 2012, 12:24 AM