Несмотря на то, что я не могу воспроизвести эту проблему, у меня есть идея, как ее исправить.
В настоящее время у вас есть DataSetEvent
, а не DataChangedEvent
.
class MyBackEndClass
{
public event EventHandler DataChanged;
private string data = string.Empty;
public string Data
{
get { return this.data; }
set
{
// Check if data has actually changed
if (this.data != value)
{
this.data = value;
//Fire the DataChanged event
}
}
}
}
Это должно остановить рекурсию, потому что теперь вы получаете TextBoxTextChanged-> DataChanged-> TextBoxChanged -> Данные не изменились, здесь прекращаются события.
РЕДАКТИРОВАТЬ: Возможно, переместите этот код в TextBox, чтобы убрать мерцание:
Замените свои System.Windows.Forms.TextBox
на:
class CleverTextBox : TextBox
{
private string previousText = string.Empty;
public CleverTextBox() : base()
{
// Maybe set the value here, not sure if this is necessary..?
this.previousText = base.Text;
}
public override OnTextChanged(EventArgs e)
{
// Only raise the event if the text actually changed
if (this.previousText != base.Text)
{
this.previousText = this.Text;
base.OnTextChanged(e);
}
}
}