WPF 学习笔记(九)

一、菜单的创建

<Window x:Class="WpfApplication6.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Menu Height="23" HorizontalAlignment="Left" Margin="1">
            <MenuItem Header="文件">
                <MenuItem Header="打开"></MenuItem>
            </MenuItem>
            <MenuItem Header="编辑">
                <MenuItem Header="后退"></MenuItem>
            </MenuItem>
        </Menu>
    </Grid>
</Window>

二、菜单的常用布局选项  DockPanel

<Window x:Class="WpfApplication6.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <DockPanel>
            <Menu DockPanel.Dock="Top">
                <MenuItem Header="文件">
                    <MenuItem Header="打开" Click="MenuItem_Click"></MenuItem>
                </MenuItem>                
            </Menu>
            <TextBox DockPanel.Dock="Bottom"></TextBox>
        </DockPanel>
    </Grid>
</Window>

三、工具栏 关于按钮也可以添加icon格式的图标,<button> <button.content><image></image></button.content></button>

<Window x:Class="WpfApplication6.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <DockPanel>
            <Menu DockPanel.Dock="Top">
                <MenuItem Header="文件">
                    <MenuItem Header="打开" Click="MenuItem_Click"></MenuItem>
                </MenuItem>                
            </Menu>
            <TextBox DockPanel.Dock="left"></TextBox>
            <ToolBar DockPanel.Dock="Bottom">
                <Button Content="1"></Button>
            </ToolBar>
        </DockPanel>
    </Grid>
</Window>

 

posted @ 2018-08-26 22:16  CJin  阅读(167)  评论(0编辑  收藏  举报