Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF: binding to custom class property. PropertyChanged is fired but view does not update
    text
    copied!<p>I have a custom class Spieltag containing a property SpieltagDaten (custom class). SPieltagDaten has a property called SpieleGespielt. I have set this property as target of a binding on textbox text-property. </p> <p>The binding works just fine as the initial value of the property is beeing displayed but when the property changes the textbox is not beeing updated. </p> <p>The PropertyChanged event is fired and the parameter is spelled correctly.</p> <p>This is what the code looks like:</p> <p>This is the textbox with binding:</p> <pre class="lang-xml prettyprint-override"><code>&lt;TextBlock Name="textBlockGespielt" Text="{Binding Path=MySpieltag.Daten, Converter={util:SpieltagDatenToStringConverter}, ConverterParameter=SpieleGespielt, UpdateSourceTrigger=PropertyChanged}" /&gt; </code></pre> <p>In constructor of the window I set</p> <pre><code>this.DataContext = this; </code></pre> <p>This is the root-class of the model containing a property called Daten:</p> <pre><code>public class Spieltag : ModelBase { private ISpieltagDaten daten; public ISpieltagDaten Daten { get { return daten; } set { daten = value; Changed("Daten"); } } } </code></pre> <p>SpieltagDaten contains a property SpieleGespielt</p> <pre><code>public class SpieltagDaten : ModelBase, interfaces.ISpieltagDaten { private int _spieleGespielt; public Int32 SpieleGespielt { get { return _spieleGespielt; } set { _spieleGespielt = value; Changed("SpieleGespielt"); } } } </code></pre> <p>ModelBase implements INotifyPropertyChanged:</p> <pre><code>public class ModelBase: INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged = delegate { }; protected void Changed(String propertyName) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(propertyName)); } } } </code></pre> <p>edit:</p> <p>I forget to post the Converter. It's derived from MarkupExtension so I can use it easy in xaml:</p> <pre><code>class SpieltagDatenToStringConverter : MarkupExtension, IValueConverter { private static SpieltagDatenToStringConverter _converter = null; public override object ProvideValue(IServiceProvider serviceProvider) { if (_converter == null) { _converter = new SpieltagDatenToStringConverter(); } return _converter; } public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { ISpieltagDaten daten = (ISpieltagDaten)value; string res = String.Empty; string propertyName = parameter.ToString(); PropertyInfo pi = typeof(ISpieltagDaten).GetProperty(propertyName); if (pi != null) { res = pi.GetValue(daten,null).ToString(); } return res; } public object ConvertBack(object values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } </code></pre> <p>The converter is beeing called on the initial setup of the model. <img src="https://i.stack.imgur.com/xEnot.jpg" alt="enter image description here"></p>
 

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