<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Press F1 to get help" Height="250" Width="400">
<DockPanel>
<Menu DockPanel.Dock ="Top" HorizontalAlignment="Left" Background="White">
<MenuItem Header="_Edit">
<MenuItem Command ="Copy"/>
<MenuItem Command ="Cut"/>
<MenuItem Command ="Paste"/>
</MenuItem>
</Menu>
<TextBox AcceptsReturn ="True" Foreground ="Black" Background ="AliceBlue"></TextBox>
</DockPanel>
</Window>
//File:Window.xaml.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace WpfApplication1
{
public partial class MainWindow : System.Windows.Window
{
public MainWindow()
{
InitializeComponent();
CommandBinding helpBinding = new CommandBinding(ApplicationCommands.Help);
helpBinding.CanExecute += CanHelpExecute;
helpBinding.Executed += HelpExecuted;
CommandBindings.Add(helpBinding);
}
private void CanHelpExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
private void HelpExecuted(object sender, ExecutedRoutedEventArgs e)
{
MessageBox.Show("support", "Help!");
}
}
}
|