Posted by: Zeeshan Amjad | February 17, 2010

Using Built in Commands with Tool bar


We already saw the example of command binding here. WPF already provide few commands as defined in this block diagram.

WpfCommands

Now we are going to use the built in command with tool bar. Using built in commands with tool bare is in fact very easy. Unlike the command button, we don’t have to provide the command target here. If we don’t provide the command target then the current focus UIElement will be a command target. Here is one very simple program to demonstrate the built in command binding with tool bar.

  1: <Window x:Class="WpfToolBar.Window1"
  2:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4:     Title="Toolbar" Height="300" Width="400">
  5:     <DockPanel>
  6:         <ToolBar DockPanel.Dock="Top">
  7:             <Button Content="Cut" Command="ApplicationCommands.Cut"/>
  8:             <Button Content="Copy" Command="ApplicationCommands.Copy"/>
  9:             <Button Content="Paste" Command="ApplicationCommands.Paste"/>
 10:         </ToolBar>
 11:         <Grid>
 12:             <TextBox Margin="5" TextWrapping="Wrap" />
 13:         </Grid>
 14:     </DockPanel>
 15: </Window>
 16: 

Here is the output of this program.

ToolBarCommandBindingOutput

Advertisements

Responses

  1. […] bar is not very difficult. We have already made one program of using built in command with tool bar here. Now we are going to extend this program and introduce one combo box to select the foreground color […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: