3-WPF命令6-复制粘贴示例

This commit is contained in:
Bunny 2025-01-10 12:08:41 +08:00
parent ef55746cc7
commit da2050836a
8 changed files with 129 additions and 0 deletions

View File

@ -10,6 +10,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "3-WPF命令4-微调命令
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "3-WPF命令5-直接调用命令", "3-WPF命令5-直接调用命令\3-WPF命令5-直接调用命令.csproj", "{5BCEFFC3-E3FE-4A32-BE43-EE5FF85DDFEB}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "3-WPF命令5-直接调用命令", "3-WPF命令5-直接调用命令\3-WPF命令5-直接调用命令.csproj", "{5BCEFFC3-E3FE-4A32-BE43-EE5FF85DDFEB}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "3-WPF命令6-复制粘贴示例", "3-WPF命令6-复制粘贴示例\3-WPF命令6-复制粘贴示例.csproj", "{319276CC-0EE8-49C6-83FA-6217C95BAE15}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -36,5 +38,9 @@ Global
{5BCEFFC3-E3FE-4A32-BE43-EE5FF85DDFEB}.Debug|Any CPU.Build.0 = Debug|Any CPU {5BCEFFC3-E3FE-4A32-BE43-EE5FF85DDFEB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5BCEFFC3-E3FE-4A32-BE43-EE5FF85DDFEB}.Release|Any CPU.ActiveCfg = Release|Any CPU {5BCEFFC3-E3FE-4A32-BE43-EE5FF85DDFEB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5BCEFFC3-E3FE-4A32-BE43-EE5FF85DDFEB}.Release|Any CPU.Build.0 = Release|Any CPU {5BCEFFC3-E3FE-4A32-BE43-EE5FF85DDFEB}.Release|Any CPU.Build.0 = Release|Any CPU
{319276CC-0EE8-49C6-83FA-6217C95BAE15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{319276CC-0EE8-49C6-83FA-6217C95BAE15}.Debug|Any CPU.Build.0 = Debug|Any CPU
{319276CC-0EE8-49C6-83FA-6217C95BAE15}.Release|Any CPU.ActiveCfg = Release|Any CPU
{319276CC-0EE8-49C6-83FA-6217C95BAE15}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

View File

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<RootNamespace>_3_WPF命令6_复制粘贴示例</RootNamespace>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<Resource Include="public\003540AH4M72.jpg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
</ItemGroup>
</Project>

View File

@ -0,0 +1,9 @@
<Application x:Class="_3_WPF命令6_复制粘贴示例.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:_3_WPF命令6_复制粘贴示例"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>

View File

@ -0,0 +1,12 @@
using System.Configuration;
using System.Data;
using System.Windows;
namespace _3_WPF命令6_复制粘贴示例;
/// <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,30 @@
<Window x:Class="_3_WPF命令6_复制粘贴示例.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"
Icon="public/003540AH4M72.jpg" Title="_3_WPF命令6_复制粘贴示例" Height="450" Width="800">
<Window.CommandBindings>
<CommandBinding Command="New" Executed="CommandBinding_OnExecuted" />
<CommandBinding Command="Cut" Executed="CommandBindingCut_OnExecuted" />
<CommandBinding Command="Copy" Executed="CommandBindingCopy_OnExecuted" />
<CommandBinding Command="Paste" Executed="CommandBindingPast_OnExecuted" />
</Window.CommandBindings>
<StackPanel>
<Menu>
<MenuItem Header="文件">
<MenuItem Command="New" />
</MenuItem>
<MenuItem Header="编辑">
<MenuItem Command="Cut" />
<MenuItem Command="Copy" />
<MenuItem Command="Paste" />
</MenuItem>
</Menu>
<TextBox Height="300" Name="TestTextBox" TextWrapping="Wrap" AcceptsReturn="True" AcceptsTab="True"
BorderBrush="PaleVioletRed" BorderThickness="5" />
</StackPanel>
</Window>

View File

@ -0,0 +1,44 @@
using System.Windows;
using System.Windows.Input;
namespace _3_WPF命令6_复制粘贴示例;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private const string NewText = "新建。。。";
private const string CopyText = "复制。。。";
private const string CutText = "剪切。。。";
private const string PastText = "粘贴。。。";
public MainWindow()
{
InitializeComponent();
}
private void CommandBinding_OnExecuted(object sender, ExecutedRoutedEventArgs e)
{
Console.WriteLine(NewText);
TestTextBox.Text += NewText;
}
private void CommandBindingCut_OnExecuted(object sender, ExecutedRoutedEventArgs e)
{
Console.WriteLine(CutText);
TestTextBox.Text += CutText;
}
private void CommandBindingCopy_OnExecuted(object sender, ExecutedRoutedEventArgs e)
{
Console.WriteLine(CopyText);
TestTextBox.Text += CopyText;
}
private void CommandBindingPast_OnExecuted(object sender, ExecutedRoutedEventArgs e)
{
Console.WriteLine(PastText);
TestTextBox.Text += PastText;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB