本次仅模仿Windows记事本的模样,并未实现其功能。
所有代码如下:
XML
<Window x:Class="控件的基础使用.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:控件的基础使用"
mc:Ignorable="d"
Title="记事本" Height="700" Width="800">
<Grid>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="600"/>
<RowDefinition Height="20"/>
</Grid.RowDefinitions>
<Menu Background="White" Grid.Row="0">
<MenuItem Header="文件">
<MenuItem Header="新建标签页"/>
<MenuItem Header="新建窗口"/>
<MenuItem Header="打开"/>
<MenuItem Header="保存"/>
<MenuItem Header="另存为"/>
<MenuItem Header="全部保存"/>
<MenuItem Header="页面设置"/>
<MenuItem Header="打印"/>
<MenuItem Header="关闭选项卡"/>
<MenuItem Header="关闭窗口"/>
<MenuItem Header="退出"/>
</MenuItem>
<MenuItem Header="编辑">
<MenuItem Header="撤销"/>
<MenuItem Header="剪切"/>
<MenuItem Header="复制"/>
<MenuItem Header="粘贴"/>
<MenuItem Header="删除"/>
<MenuItem Header="查找"/>
<MenuItem Header="查找下一个"/>
<MenuItem Header="查找上一个"/>
<MenuItem Header="替换"/>
<MenuItem Header="转到"/>
<MenuItem Header="全选"/>
<MenuItem Header="时间/日期"/>
<MenuItem Header="字体"/>
</MenuItem>
<MenuItem Header="查看">
<MenuItem Header="缩放">
<MenuItem Header="放大"/>
<MenuItem Header="缩小"/>
<MenuItem Header="还原默认缩放"/>
</MenuItem>
<MenuItem Header="状态栏"/>
<MenuItem Header="自动换行"/>
</MenuItem>
</Menu>
<RichTextBox Grid.Row="1" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible"/>
<StackPanel Grid.Row="2" Orientation="Horizontal" Background="White">
<TextBlock Text="行,列" Margin="50,0,0,0"/>
<TextBlock Text="100%" Margin="50,0,0,0"/>
<TextBlock Text="windows(CRLF)" Margin="50,0,0,0"/>
<TextBlock Text="UTF-8" Margin="50,0,0,0"/>
</StackPanel>
</Grid>
</Grid>
</Window>
cs
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 控件的基础使用
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}
菜单: