WPF - A simple text Editor in less than 20 lines of markup!


So powerful is WPF that you can write, in less than 20 lines of markup (with zero code behind), a simple text editor... with spell checking!

All you need do is put the following XAML into your favourite text editor and compile:

<Window x:Class="SimpleXAMLTextEditor.Window1"
    Title="SimpleXAMLTextEditor" Height="300" Width="300">
    <Menu DockPanel.Dock="Top">
      <MenuItem Header="Edit">
        <MenuItem Command="Cut" Header="_Cut" />
        <MenuItem Command="Copy" Header="C_opy" />
        <MenuItem Command="Paste" Header="_Paste" />
    <ToolBarTray DockPanel.Dock="Top">
        <Button Command="Cut" Content="Cut" />
        <Button Command="Copy" Content="Copy" />
        <Button Command="Paste" Content="Paste" />
    <TextBox SpellCheck.IsEnabled="True" />

This produces a very simple application:


No code is required because the WPF team have already implemented the standard edit commands[*] for the TextBox and RichTextBox controls. You also get spelling for free by just adding one attribute.

Do the WPF team rock or what!

[*] For more on commands check out my previous post on the subject.


JohnP said...

Wow thats a great example, Ta.

Anonymous said...

Great example!

Anonymous said...

Great Example!