TextBox.Text binding error when working in Windows XP

I noticed an interesting bug in WPF, and I wondered if anyone else had seen it, and if so, how did they get around this?

I have a Window , and inside there is a GroupBox inside which there is a TextBox . DataContext on the GroupBox set to an object inside my program, and as a result, the binding to the TextBox set as follows:

 <TextBox Text="{Binding Directory_Data}" IsReadOnly="True" Name="dataPath_TextBox" Grid.Column="0" Grid.Row="1" Height="23" Margin="6,3,3,3"/> 

On Windows 7 (which I am developing) this works fine, and I had no reason to even think twice about this XAML line. However, during some tests in Windows XP (with .NET4.0 installed), opening this Window caused the entire program to crash with this error:

EventType: clr20r3, system.invalidoperationexception.

It took me a long time to work with the code until I finally narrowed it down to the XAML line.

Changing the TextBox to Label (and changing the Text property to Content ) prevented this failure, and the program worked as planned; this is just a TextBox error.

Although you can simply switch the TextBox to the Label (given that in my case it will be ReadOnly ), I would prefer a TextBox for the look. Maybe I need to update the Text property manually from the code below.

In any case, basically, I just wanted to point out this problem if someone else encounters something like this. Any thoughts on why this, however, would be appreciated.

+4
source share
1 answer

From the suggestions in the comments, I implemented an AppDomain.UnhandledException as described here. I put the code before:

app.InitializeComponent();

app.Run();

This was then done for output to a MessageBox ). By then, having recreated the problem, I received the following message:

"Binding TwoWay or OneWayToSource cannot work as a read-only property of a TextBox .

Changing it to OneWay solves the problem, although why it is happening on XP, and not on Windows 7, I'm not sure. Doing TextBox not ReadOnly will also work, although in my case I want it to remain ReadOnly .

0
source

Source: https://habr.com/ru/post/1432423/


All Articles