In my complex program TextBox.Text
is interconnected with Grid.Width
.
When I clear TextBox
, .NET is crashed.
The problem is that inside TextBox.TextChanged
I set Grid.Width
and inside Grid.SizeChanged
I set TextBox.Text
. Thus, TextBox.Text
is set inside two nested event handlers.
Could anyone help to fix this bug without Timer
or Binding
?
The runtime has encountered a fatal error. The address of the error was at 0x6c05e4ad, on thread 0x2844. The error code is 0x80131623. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.
I created a test WPF app to check this bug separately.
XAML:
<Grid Height="350">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="350" />
<ColumnDefinition Width="350" />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0"
x:Name="grid"
Width="300"
Height="300"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Background="Red"
SizeChanged="grid_SizeChanged" />
<TextBox Grid.Column="1"
x:Name="text"
Text="300"
TextChanged="text_TextChanged" />
</Grid>
Code behind:
private void grid_SizeChanged(object sender, SizeChangedEventArgs e)
{
text.Text = grid.Width.ToString();
}
private void text_TextChanged(object sender, TextChangedEventArgs e)
{
if (text.Text == "")
grid.Width = double.NaN;
}
I solved this problem by using the Dispatcher:
private void grid_SizeChanged(object sender, SizeChangedEventArgs e)
{
//text.Text = grid.Width.ToString();
Dispatcher.BeginInvoke(new Action(() => text.Text = grid.Width.ToString()));
}
Thank you all for "help" and negative rating.
User contributions licensed under CC BY-SA 3.0