tbiro.com

Forums 
   HackPerfCounter
   RADPass
   SHEdit
   Toys
 
   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"
    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>
        <Menu Height="22" Name="topMenu" VerticalAlignment="Top">
            <MenuItem Header="_File">
                <MenuItem Header="E_xit" Name="menuItemExit" Click="menuItemExit_Click" ></MenuItem>
            </MenuItem>
            <MenuItem Header="_Edit">
                <MenuItem Command="ApplicationCommands.Cut"/>
                <MenuItem Command="ApplicationCommands.Copy"/>
                <MenuItem Command="ApplicationCommands.Paste"/>
            </MenuItem>
            <MenuItem Header="_Hello!"  Name="menuItemHello" Click="menuItemHello_Click"></MenuItem>

        </Menu>

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


    </Grid>
</Window>



Paste this code into Window1.xaml.cs:

using System.Windows;

namespace HelloFromMenu
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

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

        private void menuItemExit_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }
    }
}

Compile and run.


Comment in the forum





Sitemap generated by Sitemap Manager