feat: WPF控件-13-TextBox

This commit is contained in:
Bunny 2025-01-08 17:56:47 +08:00
parent ade2d5bae6
commit 1cb02af7d1
7 changed files with 97 additions and 0 deletions

View File

@ -0,0 +1,9 @@
<Application x:Class="WPF控件_13_TextBox.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPF控件_13_TextBox"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>

View File

@ -0,0 +1,12 @@
using System.Configuration;
using System.Data;
using System.Windows;
namespace WPF控件_13_TextBox;
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}

View File

@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

View File

@ -0,0 +1,15 @@
<Window x:Class="WPF控件_13_TextBox.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"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<StackPanel>
<StackPanel Orientation="Horizontal">
<Button Name="UndoButton" Content="撤销" Click="UndoButton_OnClick" />
</StackPanel>
<TextBox Name="TextBox" TextWrapping="Wrap" AcceptsReturn="True" AutoWordSelection="True" IsUndoEnabled="True"
SpellCheck.IsEnabled="True" Loaded="TextBox_OnLoaded" />
</StackPanel>
</Window>

View File

@ -0,0 +1,33 @@
using System.Windows;
namespace WPF控件_13_TextBox;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void TextBox_OnLoaded(object sender, RoutedEventArgs e)
{
TextBox.Text =
"TextWrapping=\"Wrap\" 是否换行 \n" +
" AcceptsReturn=\"True\" 收否回车键换行 \n" +
" AutoWordSelection=\"True\" 自动选择文本单词 \n " +
"IsUndoEnabled=\"False\" 是否开启Undo";
}
private void UndoButton_OnClick(object sender, RoutedEventArgs e)
{
var undo = TextBox.Undo();
Console.WriteLine($"undo{undo}");
var textBoxCanUndo = TextBox.CanUndo;
var canUndo = $"TextBox can undo: {textBoxCanUndo}";
Console.WriteLine(canUndo);
}
}

View File

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<RootNamespace>WPF控件_13_TextBox</RootNamespace>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>

View File

@ -28,6 +28,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF控件-11-Expander2", "W
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF控件-12-多文本", "WPF控件-12-多文本\WPF控件-12-多文本.csproj", "{45A695BD-4B02-47F4-8598-144E882A8CF6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF控件-13-TextBox", "WPF控件-13-TextBox\WPF控件-13-TextBox.csproj", "{C53C3922-EB39-48E7-B88E-7552BDBE839D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -90,5 +92,9 @@ Global
{45A695BD-4B02-47F4-8598-144E882A8CF6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{45A695BD-4B02-47F4-8598-144E882A8CF6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{45A695BD-4B02-47F4-8598-144E882A8CF6}.Release|Any CPU.Build.0 = Release|Any CPU
{C53C3922-EB39-48E7-B88E-7552BDBE839D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C53C3922-EB39-48E7-B88E-7552BDBE839D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C53C3922-EB39-48E7-B88E-7552BDBE839D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C53C3922-EB39-48E7-B88E-7552BDBE839D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal