Context menu sample
How to get this code going: Create a Windows Presentation Foundation project named ContextMenuSample and paste the following code in the specified file.
Paste this code into Window1.xaml:
<Window x:Class="ContextMenuSample.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<TextBox Margin="20,20,28,47" Name="textBox1" TextWrapping="Wrap">
<TextBox.ContextMenu>
<ContextMenu>
<MenuItem Command="ApplicationCommands.Paste"></MenuItem>
<MenuItem Command="ApplicationCommands.Copy"></MenuItem>
<MenuItem Command="ApplicationCommands.Cut"></MenuItem>
</ContextMenu>
</TextBox.ContextMenu>
Right-click on me to see the context menu. Select text to cut and paste from the context menu.
</TextBox>
</Grid>
</Window>
Compile and run.
|