Daily Archives: June 6, 2007

Creating Commands in XAML only

Standard

Previously I posted an article about defining “Commands” in WPF applications and responding in code.

A way of doing this in XAML only is setting up a binding to a property on another control.

In this example, a toggle button is used to toggle the blod state on a rich text box.

For example:

<Toolbar>

<ToggleButton MinWidth="40" Command="EditingCommands.ToggleBold" CommandTarget="{Binding ElementName=XAMLRichBox}" TextBlock.FontWeight="Bold">B</ToggleButton>

</Toolbar>

 

I got this idea from this article: Mastering the WPF RichTextBox