Value Value in the Property Grid - Silverlight 5

In the example below, we bound the ViewModel to a view with a single property called Message. This property is bound to a two-way TextBox. For this test, we do some sort of compulsion of value in the setter and again increase the property.

In Silverlight 4, this worked perfectly. If the message property has changed in the property adjuster, the text box will see the new value. For instance. typing "A" in the text box and losing focus will cause Aaaaaaaaaaa to appear when the value changes.

However, in Silverlight 5 it seems broken / changed. A getter never hits after changing the value in the setter. Adding an IValueConverter intermediate converter shows that the Convert / ConvertBack methods never fail. Something fundamental seems to have changed between versions 4 and 5. Have there been any changes? This is mistake?

public class ViewModel : INotifyPropertyChanged { private string _message; public event PropertyChangedEventHandler PropertyChanged; public string Message { get { return _message; } set { _message = value; this.RaisePropertyChanged(); if (_message.Length < 10) { _message = _message.PadRight(10, 'a'); this.RaisePropertyChanged(); } } } private void RaisePropertyChanged() { var handler = this.PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs("Message")); } } } 
+6
source share
2 answers

This is confirmed as a bug in Silverlight 5 from Microsoft. This only happens in debug mode, so it’s great for release mode.

If you disable XAML debugging, the problem will disappear.

 Binding.IsDebuggingEnabled = false; 
+1
source

There are several workarounds for this issue, which appears to be a bug in the Silverlight 5 debugging feature (see @Ray Booysen's answer).

Firstly, it is important to know that this is not a production problem, but rather only occurs when debugging an application. Therefore, workarounds are only valid for reproducing production behavior in a debugging environment (although some of the debugging features are disabled).

The first of the jobs is disabling mandatory debugging using the static (shared in VB.Net) field named IsDebuggingEnabled in the Binding class. The documentation has the following recommendation.

set this field to false in the constructor of the application class

Note. This change cannot be limited to a single binding, but rather will affect all the bindings in the application.

Secondly, disable the Silverlight debugger in the project properties for the web project hosting the Silverlight application. Make this change by following these steps.

  • Right-click the web project in Solution Explorer and select Properties.
  • Select the Web tab.
  • Go to the Debuggers section.
  • Uncheck the box that says Silverlight.

Note. This change disables not only mandatory debugging for the application, but also general Silverlight debugging. However, other debuggers can be enabled.

+3
source

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