Contact me
   My PGP Key

Hello WPF (from menu)

How to get this code going: Create a Windows Presentation Foundation project named HelloFromMenu and paste the following code in the specified file.

Paste this code into Window1.xaml:

<Window x:Class="HelloFromMenu.Window1"
    Title="Window1" Height="300" Width="300">
        <Menu Height="22" Name="topMenu" VerticalAlignment="Top">
            <MenuItem Header="_File">
                <MenuItem Header="E_xit" Name="menuItemExit" Click="menuItemExit_Click" ></MenuItem>
            <MenuItem Header="_Edit">
                <MenuItem Command="ApplicationCommands.Cut"/>
                <MenuItem Command="ApplicationCommands.Copy"/>
                <MenuItem Command="ApplicationCommands.Paste"/>
            <MenuItem Header="_Hello!"  Name="menuItemHello" Click="menuItemHello_Click"></MenuItem>


        <TextBox Margin="25,59,25,0"
               TextWrapping="Wrap" Height="65" VerticalAlignment="Top">
            Test cut &amp; pasting here


Paste this code into Window1.xaml.cs:

using System.Windows;

namespace HelloFromMenu
    public partial class Window1 : Window
        public Window1()

        private void menuItemHello_Click(object sender, RoutedEventArgs e)
            MessageBox.Show("Hello world!");

        private void menuItemExit_Click(object sender, RoutedEventArgs e)

Compile and run.

Comment in the forum

Sitemap generated by Sitemap Manager