WPF, XAML

wpf 메뉴다루기, menu, menuitem

오라클왕 0 235 02.23 11:31

[MainWindow.xaml]

 

<Window x:Class="WpfApp1.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

        xmlns:local="clr-namespace:WpfApp1"

        mc:Ignorable="d"

        Title="MainWindow" Height="350" Width="525">

    <DockPanel>

        <Menu DockPanel.Dock="Top">

            <MenuItem Header="_File">

                <MenuItem Header="_New" />

                <MenuItem Header="_Open" />

                <MenuItem Header="_Save" />

                <Separator />

                <MenuItem Header="_Exit" Click="OnExit" />

            </MenuItem>

        </Menu>

        <TextBox AcceptsReturn="True" />

    </DockPanel>

</Window>




[MainWindow.xaml.cs]

using System;
using System.Windows;

namespace WpfApp1
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void OnExit(object sender, RoutedEventArgs e)
        {
            //Application.Current.Shutdown();
            Environment.Exit(0);
        }
    }
}

Comments