步骤编辑相关修改
This commit is contained in:
commit
4f9195c552
13 files changed
+2386
-307
No files matched your search
@@ -0,0 +1,132 @@
|
||||
<Window x:Class="SunlightCentralizedControlManagement_SCCM_.KEY.TouchKeyboard"
|
||||
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:SunlightCentralizedControlManagement_SCCM_.WindowsView"
|
||||
mc:Ignorable="d" WindowStyle="None" ResizeMode="NoResize" Topmost="True"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
Title="TouchKeyboard" Height="500" Width="750">
|
||||
<Window.Resources>
|
||||
<Style x:Key="KeyButtonStyle" TargetType="Button">
|
||||
<Setter Property="Background" Value="#FFF0F0F0"/>
|
||||
<Setter Property="BorderBrush" Value="#FFCCCCCC"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="FontSize" Value="20"/>
|
||||
<Setter Property="FontWeight" Value="Bold"/>
|
||||
<Setter Property="Margin" Value="2"/>
|
||||
<Setter Property="MinWidth" Value="60"/>
|
||||
<Setter Property="MinHeight" Value="40"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<Border x:Name="border"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="4">
|
||||
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsPressed" Value="True">
|
||||
<Setter Property="Background" Value="#FFDDDDDD"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="SpecialKeyButtonStyle" BasedOn="{StaticResource KeyButtonStyle}" TargetType="Button">
|
||||
<Setter Property="Background" Value="#FFE0E0E0"/>
|
||||
<Setter Property="FontSize" Value="16"/>
|
||||
</Style>
|
||||
</Window.Resources>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 预览区域 -->
|
||||
<TextBox x:Name="PreviewTextBox" Grid.Row="0" Height="60" Margin="10"
|
||||
FontSize="24" VerticalContentAlignment="Center" IsReadOnly="False"/>
|
||||
|
||||
<!-- 键盘主体区域 -->
|
||||
<Grid Grid.Row="1" Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 数字行 -->
|
||||
<StackPanel Orientation="Horizontal" Grid.Row="0" HorizontalAlignment="Center">
|
||||
<Button Content="1" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="2" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="3" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="4" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="5" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="6" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="7" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="8" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="9" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="0" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="DEL" Style="{StaticResource SpecialKeyButtonStyle}" Click="Backspace_Click" Width="60"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 第一行字母 -->
|
||||
<StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Center">
|
||||
<Button Content="Q" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="W" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="E" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="R" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="T" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="Y" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="U" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="I" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="O" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="P" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 第二行字母 -->
|
||||
<StackPanel Orientation="Horizontal" Grid.Row="2" HorizontalAlignment="Center">
|
||||
<Button Content="A" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="S" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="D" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="F" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="G" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="H" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="J" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="K" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="L" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="/" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="HIDE" Style="{StaticResource SpecialKeyButtonStyle}" Click="Hide_Click" Width="60"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 第三行字母 -->
|
||||
<StackPanel Orientation="Horizontal" Grid.Row="3" HorizontalAlignment="Center">
|
||||
<Button x:Name="ShiftButton" Content="⇧" Style="{StaticResource SpecialKeyButtonStyle}" Click="Shift_Click" Width="60"/>
|
||||
<Button Content="Z" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="X" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="C" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="V" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="B" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="N" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="M" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="." Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="ENTER" Style="{StaticResource SpecialKeyButtonStyle}" Click="Enter_Click" Width="120"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<!-- 状态栏 -->
|
||||
<StatusBar Grid.Row="2">
|
||||
<StatusBarItem>
|
||||
<TextBlock x:Name="StatusTextBlock" Text="就绪"/>
|
||||
</StatusBarItem>
|
||||
</StatusBar>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,116 @@
|
||||
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.Shapes;
|
||||
using static SunlightCentralizedControlManagement_SCCM_.KEY.TouchKeyboardNumeral;
|
||||
|
||||
namespace SunlightCentralizedControlManagement_SCCM_.KEY
|
||||
{
|
||||
/// <summary>
|
||||
/// TouchKeyboard.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class TouchKeyboard : Window
|
||||
{
|
||||
private bool isShiftActive = false;
|
||||
public string KeyValue;
|
||||
public event EventHandler<KeyPressedEventArgs> KeyPressed;
|
||||
|
||||
public TouchKeyboard()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void KeyButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Button button = sender as Button;
|
||||
if (button != null)
|
||||
{
|
||||
string key = button.Content.ToString();
|
||||
|
||||
if (key.Length == 1 && char.IsLetter(key[0]))
|
||||
{
|
||||
key = isShiftActive ? key.ToUpper() : key.ToLower();
|
||||
}
|
||||
|
||||
PreviewTextBox.Text += key;
|
||||
|
||||
// 输入后关闭Shift状态
|
||||
if (isShiftActive)
|
||||
{
|
||||
isShiftActive = false;
|
||||
UpdateButtonAppearance();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Shift_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
isShiftActive = !isShiftActive;
|
||||
UpdateButtonAppearance();
|
||||
}
|
||||
|
||||
private void Backspace_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(PreviewTextBox.Text))
|
||||
{
|
||||
PreviewTextBox.Text = PreviewTextBox.Text.Substring(0, PreviewTextBox.Text.Length - 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void Enter_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// 触发回车事件
|
||||
KeyPressed?.Invoke(this, new KeyPressedEventArgs(KeyType.Enter, PreviewTextBox.Text));
|
||||
|
||||
this.Close();
|
||||
// PreviewTextBox.Text += Environment.NewLine;
|
||||
}
|
||||
|
||||
private void Hide_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
KeyPressed?.Invoke(this, new KeyPressedEventArgs(KeyType.Hide, ""));
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void UpdateButtonAppearance()
|
||||
{
|
||||
// 更新Shift按钮的外观以反映当前状态
|
||||
if (isShiftActive)
|
||||
{
|
||||
ShiftButton.Background = new SolidColorBrush(Colors.LightBlue);
|
||||
}
|
||||
else
|
||||
{
|
||||
ShiftButton.Background = new SolidColorBrush(Color.FromRgb(224, 224, 224));
|
||||
}
|
||||
}
|
||||
|
||||
public class KeyPressedEventArgs : EventArgs
|
||||
{
|
||||
public KeyType KeyType { get; }
|
||||
public string KeyValue { get; }
|
||||
|
||||
public KeyPressedEventArgs(KeyType keyType, string keyValue)
|
||||
{
|
||||
KeyType = keyType;
|
||||
KeyValue = keyValue;
|
||||
}
|
||||
}
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// 初始化为默认模式
|
||||
// SetKeyboardMode(KeyboardMode.Default);
|
||||
PreviewTextBox.Text = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<Window x:Class="SunlightCentralizedControlManagement_SCCM_.KEY.TouchKeyboardNumeral"
|
||||
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:SunlightCentralizedControlManagement_SCCM_.WindowsView"
|
||||
mc:Ignorable="d"
|
||||
WindowStyle="None"
|
||||
ResizeMode="NoResize"
|
||||
Topmost="True"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
Title="TouchKeyboardNumeral"
|
||||
Loaded="Window_Loaded"
|
||||
Height="500" Width="550">
|
||||
<Window.Resources>
|
||||
<Style x:Key="KeyButtonStyle" TargetType="Button">
|
||||
<Setter Property="Background" Value="#FFF0F0F0"/>
|
||||
<Setter Property="BorderBrush" Value="#FFCCCCCC"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="FontSize" Value="20"/>
|
||||
<Setter Property="FontWeight" Value="Bold"/>
|
||||
<Setter Property="Margin" Value="2"/>
|
||||
<Setter Property="MinWidth" Value="100"/>
|
||||
<Setter Property="MinHeight" Value="40"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<Border x:Name="border"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="4">
|
||||
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsPressed" Value="True">
|
||||
<Setter Property="Background" Value="#FFDDDDDD"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="Foreground" Value="#FFBBBBBB"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="SpecialKeyButtonStyle" BasedOn="{StaticResource KeyButtonStyle}" TargetType="Button">
|
||||
<Setter Property="Background" Value="#FFE0E0E0"/>
|
||||
<Setter Property="FontSize" Value="16"/>
|
||||
</Style>
|
||||
</Window.Resources>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 预览区域 -->
|
||||
<TextBox x:Name="PreviewTextBox" Grid.Row="0" Height="60" Margin="10"
|
||||
FontSize="24" VerticalContentAlignment="Center" IsReadOnly="False"/>
|
||||
|
||||
<!-- 键盘主体区域 -->
|
||||
<Grid Grid.Row="1" Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 数字行 -->
|
||||
<StackPanel x:Name="FirstRow" Orientation="Horizontal" Grid.Row="0" HorizontalAlignment="Center">
|
||||
<Button Content="7" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="8" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="9" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="0" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="DEL" Style="{StaticResource SpecialKeyButtonStyle}" Click="Backspace_Click" Width="60"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 数字行 -->
|
||||
<StackPanel x:Name="SecondRow" Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Center">
|
||||
<Button Content="4" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="5" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="6" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="." Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="HIDE" Style="{StaticResource SpecialKeyButtonStyle}" Click="Hide_Click" Width="60"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 数字行 -->
|
||||
<StackPanel x:Name="ThirdRow" Orientation="Horizontal" Grid.Row="2" HorizontalAlignment="Center">
|
||||
<Button Content="1" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="2" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="3" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/>
|
||||
<Button Content="ENTER" Style="{StaticResource SpecialKeyButtonStyle}" Click="Enter_Click" Width="200"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,215 @@
|
||||
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.Shapes;
|
||||
|
||||
namespace SunlightCentralizedControlManagement_SCCM_.KEY
|
||||
{
|
||||
/// <summary>
|
||||
/// TouchKeyboard.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class TouchKeyboardNumeral : Window
|
||||
{
|
||||
private bool mode = false;
|
||||
public string KeyValue;
|
||||
public event EventHandler<KeyPressedEventArgs> KeyPressed;
|
||||
private KeyboardMode currentMode = KeyboardMode.Default;
|
||||
private int minValue = 0;
|
||||
private int maxValue = 9;
|
||||
private TextBox targetTextBox;
|
||||
// 定义键盘模式枚举
|
||||
public enum KeyboardMode
|
||||
{
|
||||
Default, // 默认模式,所有键可用
|
||||
NumericOnly, // 只允许数字
|
||||
DecimalOnly, // 允许数字和小数点
|
||||
LimitedRange // 限制数字范围
|
||||
}
|
||||
|
||||
public TouchKeyboardNumeral()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
public void SetKeyboardMode(KeyboardMode mode, TextBox target = null, int min = 0, int max = 9)
|
||||
{
|
||||
currentMode = mode;
|
||||
targetTextBox = target;
|
||||
minValue = min;
|
||||
maxValue = max;
|
||||
|
||||
UpdateKeyboardLayout();
|
||||
}
|
||||
private void UpdateKeyboardLayout()
|
||||
{
|
||||
switch (currentMode)
|
||||
{
|
||||
case KeyboardMode.NumericOnly:
|
||||
// 只允许数字,禁用小数点
|
||||
SetButtonEnabled(".", false);
|
||||
break;
|
||||
|
||||
case KeyboardMode.DecimalOnly:
|
||||
// 允许数字和小数点
|
||||
SetButtonEnabled(".", true);
|
||||
break;
|
||||
|
||||
case KeyboardMode.LimitedRange:
|
||||
// 根据范围启用/禁用数字键
|
||||
for (int i = 0; i <= 9; i++)
|
||||
{
|
||||
SetButtonEnabled(i.ToString(), i >= minValue && i <= maxValue);
|
||||
}
|
||||
mode = true;
|
||||
break;
|
||||
|
||||
case KeyboardMode.Default:
|
||||
default:
|
||||
// 启用所有键
|
||||
foreach (var element in FirstRow.Children)
|
||||
{
|
||||
if (element is Button button && char.IsDigit(button.Content.ToString()[0]))
|
||||
button.IsEnabled = true;
|
||||
}
|
||||
foreach (var element in SecondRow.Children)
|
||||
{
|
||||
if (element is Button button && (char.IsDigit(button.Content.ToString()[0]) || button.Content.ToString() == "."))
|
||||
button.IsEnabled = true;
|
||||
}
|
||||
foreach (var element in ThirdRow.Children)
|
||||
{
|
||||
if (element is Button button && char.IsDigit(button.Content.ToString()[0]))
|
||||
button.IsEnabled = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 设置按钮启用状态
|
||||
private void SetButtonEnabled(string content, bool enabled)
|
||||
{
|
||||
// 在第一行查找
|
||||
foreach (var element in FirstRow.Children)
|
||||
{
|
||||
if (element is Button button && button.Content.ToString() == content)
|
||||
{
|
||||
button.IsEnabled = enabled;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 在第二行查找
|
||||
foreach (var element in SecondRow.Children)
|
||||
{
|
||||
if (element is Button button && button.Content.ToString() == content)
|
||||
{
|
||||
button.IsEnabled = enabled;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 在第三行查找
|
||||
foreach (var element in ThirdRow.Children)
|
||||
{
|
||||
if (element is Button button && button.Content.ToString() == content)
|
||||
{
|
||||
button.IsEnabled = enabled;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 数字键点击事件
|
||||
private void KeyButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (mode && PreviewTextBox.Text.Length > 0) return;
|
||||
Button button = sender as Button;
|
||||
if (button != null && button.IsEnabled)
|
||||
{
|
||||
string keyValue = button.Content.ToString();
|
||||
PreviewTextBox.Text += keyValue;
|
||||
|
||||
// 触发按键事件
|
||||
// KeyPressed?.Invoke(this, new KeyPressedEventArgs(KeyType.Character, keyValue));
|
||||
}
|
||||
}
|
||||
|
||||
// 退格键点击事件
|
||||
private void Backspace_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (PreviewTextBox.Text.Length > 0)
|
||||
{
|
||||
PreviewTextBox.Text = PreviewTextBox.Text.Substring(0, PreviewTextBox.Text.Length - 1);
|
||||
|
||||
// 触发退格事件
|
||||
// KeyPressed?.Invoke(this, new KeyPressedEventArgs(KeyType.Backspace, ""));
|
||||
}
|
||||
}
|
||||
|
||||
// 回车键点击事件
|
||||
private void Enter_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// 触发回车事件
|
||||
KeyPressed?.Invoke(this, new KeyPressedEventArgs(KeyType.Enter, PreviewTextBox.Text));
|
||||
|
||||
// 隐藏键盘
|
||||
this.Hide();
|
||||
}
|
||||
|
||||
// 隐藏键点击事件
|
||||
private void Hide_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
KeyPressed?.Invoke(this, new KeyPressedEventArgs(KeyType.Hide, ""));
|
||||
// 隐藏键盘
|
||||
this.Hide();
|
||||
}
|
||||
|
||||
public class KeyPressedEventArgs : EventArgs
|
||||
{
|
||||
public KeyType KeyType { get; }
|
||||
public string KeyValue { get; }
|
||||
|
||||
public KeyPressedEventArgs(KeyType keyType, string keyValue)
|
||||
{
|
||||
KeyType = keyType;
|
||||
KeyValue = keyValue;
|
||||
}
|
||||
}
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// 初始化为默认模式
|
||||
// SetKeyboardMode(KeyboardMode.Default);
|
||||
PreviewTextBox.Text = null;
|
||||
mode = false;
|
||||
}
|
||||
}
|
||||
// 按键类型枚举
|
||||
public enum KeyType
|
||||
{
|
||||
Character,
|
||||
Backspace,
|
||||
Enter,
|
||||
Hide
|
||||
}
|
||||
|
||||
// 按键事件参数
|
||||
public class KeyPressedEventArgs : EventArgs
|
||||
{
|
||||
public KeyType KeyType { get; }
|
||||
public string KeyValue { get; }
|
||||
|
||||
public KeyPressedEventArgs(KeyType keyType, string keyValue)
|
||||
{
|
||||
KeyType = keyType;
|
||||
KeyValue = keyValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user