I have a databinding that uses the MethodToValueConverter
in this answer. This works great, however I am having difficulty forcing the view to update after the result of the method has changed. It's a little hard to explain, so hopefully some code snippits will help.
The class object
[DataContract]
public class RetentionBankItem : INotifyPropertyChanged
{
#region Private Properties
public event PropertyChangedEventHandler PropertyChanged;
private float _rbRevisedRateLoad;
private float _rbCurrentRateLoad;
#endregion
[DataMember]
public float rbRevisedRateLoad
{
get
{
return _rbRevisedRateLoad;
}
set
{
PropertyChanged.ChangeAndNotify(ref _rbRevisedRateLoad, value, () => rbRevisedRateLoad);
OnPropertyChanged("RateLoadDifference");
}
}
[DataMember]
public float rbCurrentRateLoad
{
get
{
return _rbCurrentRateLoad;
}
set
{
PropertyChanged.ChangeAndNotify(ref _rbCurrentRateLoad, value, () => rbCurrentRateLoad);
OnPropertyChanged("RateLoadDifference");
}
}
public float RateLoadDifference()
{
if (rbCurrentRateLoad != 0)
{
return rbRevisedRateLoad / rbCurrentRateLoad;
}
return 0;
}
}
It should be noted that in the following code, RetentionBank
is of type List<RetentionBankItem>
My binding looks like this:
<ItemsControl ItemsSource="{Binding RetentionBank}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding rbRevisedRateLoad, Mode=TwoWay}"
Grid.Row="2"
Grid.Column="0" />
<TextBox Text="{Binding rbCurrentRateLoad, Mode=TwoWay}"
Grid.Row="2"
Grid.Column="1" />
<TextBox Text="{Binding Path=., Converter={StaticResource ConverterMethodToValue}, ConverterParameter='RateLoadDifference', Mode=OneWay}"
Grid.Row="2"
Grid.Column="2" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
The Current and Revised rate loads are getting set properly, but after they're set the RateLoadDifference is never getting called to update. I imagine that the class object itself needs to be called to update, since that's what the textbox is actually bound to (not necessarily the method itself), but I am unsure how to do that, or if it is even the proper way to do it. Any help or suggestions would be appreciated. Thanks!