This project is read-only.

Hello, world!

To get started using Markup Programming, we are going to tackle the classic "Hello, world!" program. This is easy to do but we're trying to demonstrate principles. It's not hard but if you follow it step-by-step then less can go wrong.

  • Create a brand new WPF4 project

Now you have three choices, use NuGet to reference the package, use one of the releases or build it yourself. If you just want to try it out fast then I recommend NuGet.

To use the NuGet package:

  • In your WPF project use Tools -> Library Package Manager -> Manage NuGet Packages for Solution...
  • Search for Markup.Programming
  • Add it!

To use the preview release:

To build Markup.Programming.dll from source for yourself:

  • Download Markup Programming Source Code
  • Open the solution, choose the "Debug - WPF" configuration and build it Ctrl-Shift-B
  • Add a reference to your WPF project by browsing to (where-you-installed-the-source)\Markup.Programming\bin\WPF4\Markup.Programming.DLL

Now your project is all set you and you can start coding, oops, I mean writing markup. OK, so we've got a main window with a little XAML already in it. Let's throw in a rectangle and make it red.

        <Rectangle Fill="Red">
            <!-- to do -->

Now run the program with F5. It should compile and run and show a big red square.

Next we want to add the XML namespace for Markup.Programming like this:


The "p" prefix is for "programming" of course!

OK, so the plan is to show a message box when we click on the rectangle. Now, traditionally, at this point we would add an event handler for the MouseLeftButtonDown event, click "Navigate to Event Handler" which would take us to the code-behind for main window and we would be in C# land.

Instead, by using Markup.Programming we are going to define an event handler and what to do in that event handler all in markup. OK, so the moment of truth is at hand. We are standing at the top of the mountain ready to say hello world. How do we do it?

        <Rectangle Fill="Red">
                <p:CallHandler Path="MouseLeftButtonDown => [MessageBox].Show('Hello, world!')"/>

Paste the code in, press F5 to run and then left-click the red rectangle to trigger the event handler and sit back and listen for the echo!

Hopefully that worked. If it did, then you are all set to try your hand at markup programming. Please check out some of the other samples.

Here is the complete HelloWorld.xaml sample included with the source distribution:

    Height="300" Width="300">
        <Rectangle Fill="Red">
                <p:CallHandler Path="MouseLeftButtonDown => [MessageBox].Show('Hello, world!')"/>


Last edited Nov 12, 2012 at 6:12 AM by jrs, version 31


pauleffect Oct 1, 2014 at 2:12 PM 
this is too good to be true!