WPF的菜单栏,⼯具栏的简单使⽤1. 界⾯效果如下:
2. 页⾯ .xaml代码如下:
<Window x:Class="MenuAndToolBar.MainWindow"
xmlns="schemas.microsoft/winfx/2006/xaml/presentation"
xmlns:x="schemas.microsoft/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<DockPanel><!--停靠布局,让菜单栏和⼯具栏位于窗⼝顶部-->
<Menu DockPanel.Dock="Top">
<MenuItem Header="File"><!--菜单项为MenuItem,⽂字使⽤属性 Header-->
<MenuItem Name="menuOpen" Header="Open" Click="menuOpen_Click"></MenuItem>
<MenuItem Header="Save"></MenuItem>
<MenuItem Header="Delete"></MenuItem>
</MenuItem>
<MenuItem Header="Edit"></MenuItem>
<MenuItem Header="View"></MenuItem>
<MenuItem Header="About"></MenuItem>
</Menu>
<ToolBar DockPanel.Dock="Top"><!--ToolBar和StatusBar就是⼀个容器-->
<Button Content="Save"></Button>
<Button Content="SaveAll"></Button>
<Button Content="FileExplorer"></Button>
<Button Content="Start"></Button>
<Button Content="Test"></Button>
</ToolBar>
<TextBox DockPanel.Dock="Top" Text="This is my space" Height="243"></TextBox>
<StatusBar DockPanel.Dock="Bottom">
菜单栏包括<TextBlock Text="statusBar"></TextBlock>
</StatusBar>
</DockPanel>
</Grid>
</Window>
3. 后台代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Navigation;
using System.Windows.Shapes;
namespace MenuAndToolBar
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void menuOpen_Click(object sender, RoutedEventArgs e) {
MessageBox.Show("Open the file you want.");
}
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论