添加一个名为TouchTextBox的资源字典 。
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"x:Class="WpfApp1.TouchTextBox"><Style x:Key="TouchTextBox" TargetType="{x:Type TextBox}"><EventSetter Event="PreviewMouseLeftButtonDown" Handler="OnClick" /></Style></ResourceDictionary>四 效果展示在App.Xaml中引入TouchTextBox.Xaml资源 。
<Application x:Class="WpfApp1.App"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local="clr-namespace:WpfApp1"StartupUri="MainWindow.xaml"><Application.Resources><ResourceDictionary><ResourceDictionary.MergedDictionaries><ResourceDictionary Source="/WpfApp1;component/TouchTextBox.xaml" /></ResourceDictionary.MergedDictionaries></ResourceDictionary></Application.Resources></Application>MainWindow界面代码:
<Window x:Class="WpfApp1.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="800" Width="1200"><StackPanel><TextBox Text="Pop up the keyboard after touching" Width="400" HorizontalAlignment="Left"FontSize="18" Margin="20,20"Style="{StaticResource TouchTextBox}"/></StackPanel></Window>设置TextBox的Style为TouchTextBox,则该TextBox实现了自带触控键盘的效果 。
【WPF开发经验-实现自带触控键盘的TextBox】以上 。
经验总结扩展阅读
- 倒车雷达如何判断好坏
- 驱动开发:通过ReadFile与内核层通信
- 用golang开发系统软件的一些细节
- 三十六 Java开发学习----SpringBoot三种配置文件解析
- 在 WPF 中实现融合效果
- aardio + Python 可视化快速开发桌面程序,一键生成独立 EXE
- Windows esp-idf 安装
- aardio + PHP 可视化快速开发独立 EXE 桌面程序
- 制造企业有可能自行开发ERP系统吗?
- 农村土地开发有哪些不允许的项目