我創建了一個小的WPF應用程序,有點重新創建這種情況。 我可以通過從文本編輯器複製並將其粘貼到活動數據網格單元格中,獲得一個控制字符,如退格鍵(ASCII 8,Alt + 0008)。 注:請確保您使用數字鍵盤的ASCII碼
MainWindow.xaml:
<Window
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:BackspaceInGrid"
x:Class="BackspaceInGrid.MainWindow"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Last Update Category Value: "/>
<TextBlock Name="LastUpdateTextBlock"/>
</StackPanel>
<DataGrid x:Name="MyDataGrid" Height="300" Width="500" DataContext="" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="K" Width="40"
Binding="{Binding Category, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"/>
</DataGrid.Columns>
</DataGrid>
</StackPanel>
</Window>
MainWindow.xaml.cs:
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
namespace BackspaceInGrid
{
public class Widget : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string category;
public string Category
{
get { return category; }
set
{
category = value;
OnPropertyChanged("Category");
}
}
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
}
public partial class MainWindow : Window
{
public void CategoryChangedEvent(object sender, PropertyChangedEventArgs e)
{
Widget widget = (Widget) sender;
string categoryChars = string.Empty;
for (int i = 0; i < widget.Category.Length; i++)
{
char c = widget.Category[i];
if (char.IsControl(c))
{
categoryChars = string.Format("{0}char {1} = ASCII({2}), ", categoryChars, i, (int) c);
}
else
{
categoryChars = string.Format("{0}char {1} = '{2}', ", categoryChars, i, c);
}
}
LastUpdateTextBlock.Text = categoryChars;
}
public MainWindow()
{
InitializeComponent();
ObservableCollection<Widget> widgets = new ObservableCollection<Widget>();
widgets.Add(new Widget { Category = "ABC" });
char [] chars_abc = new char [] { (char) 97, (char) 98, (char) 99 };
char [] chars_ab_back_c = new char [] { (char) 97, (char) 98, (char) 8, (char) 99 };
widgets.Add(new Widget { Category = new string(chars_abc) });
widgets.Add(new Widget { Category = new string(chars_ab_back_c) });
foreach (Widget widget in widgets)
{
widget.PropertyChanged += CategoryChangedEvent;
}
MyDataGrid.ItemsSource = widgets;
}
}
}
您可以輕鬆地粘貼控制字符來自剪貼板。用戶可能已經複製了包含退格控制字符的字符串。這可能是文本源應用程序中的錯誤或用戶的漏洞攻擊。 – dymanoid
我親自認識用戶 - 很確定她只是簡單地輸入了一個字母(這是類別字符串的常規用途)......但是無論如何,我會試着用一些日誌來追蹤這個信息,看看它是否會再次發生。 – user3559014