Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding doesn't work after setting the property value to null
    primarykey
    data
    text
    <p>I have a DataGrid witch is bound to a ObservableCollection&lt;"Product">. The columns are bound to properties of Product. Most of then are of type double?(nullable).</p> <p>In some time I have to set some property to null. After that, no matter the value I set, the binding don't work. The value is not updated in the view.</p> <p>What happens to the binding when I set a property to null?</p> <p>I tried what is shown in this blog post <a href="http://wildermuth.com/2009/11/18/Data_Binding_Changes_in_Silverlight_4" rel="nofollow">http://wildermuth.com/2009/11/18/Data_Binding_Changes_in_Silverlight_4</a> but it didn't worked to me.</p> <p>Thanks!</p> <p><strong>Edit:</strong> Below is the class I've created that implements the INotifyPropertyChanged</p> <pre><code>public class NotifyPropertyChangedAttribute : INotifyPropertyChanged { Dictionary&lt;string, object&gt; _propBag = new Dictionary&lt;string, object&gt;(); protected object Get(string propName) { object value = null; _propBag.TryGetValue(propName, out value); return value; } protected void Set(string propName, object value) { if (!_propBag.ContainsKey(propName) || Get(propName)!=null) { _propBag[propName] = value; OnPropertyChanged(new PropertyChangedEventArgs(propName)); } } public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) { if (PropertyChanged != null) PropertyChanged(this, e); } } </code></pre> <p>This is my Product class. The DataGrid's ItemsSource property is bound to a ObservableCollection of Products:</p> <pre><code>public class Product : NotifyPropertyChangedAttribute { public string Name { get { return (string)Get("Name") ?? ""; } set { Set("Name", value); } } public double? Price { get {return (double)Get("Price") ?? null;} set { Set("Price", value);} } public void Reset() { var propertyInfo = typeof(Product).GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance); foreach (var p in propertyInfo) { p.SetValue(this , null, null); } } } </code></pre> <p>Look the Reset() method. The binding stop working after I call this method. In my app, I need that when the user press "Del" key, the DataGrid's row get empty, but can not be removed.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload