You need to implement INotifyPropertyChanged interface to your data object. WPF data binding power is mainly depends on the Notify Properties. If your data class doesn't have implemented it, it will not work as you said.
You will get better idea if you read through this
WPF: A Beginner's Guide - Part 5 of n[
^]
Update 1:
tpwright4423 wrote:
Is that happening independently of the INotifyPropertyChanged interface implementation?
Yes.
tpwright4423 wrote:
What is the default binding Mode?
Default binding mode depends on the Property/object to which you are binding
tpwright4423 wrote:
If I implement the INotifyPropertyChanged interface, will the value converter I created for setting the background color be called when a value changes or do I need to implement another converter?
Just implement the INotifyPropertyChanged interface. The current Converter is more than enough.
Update 2 (from the source code):
I have found the issue. And fixed it using IMultiValueConverter.
Your Code:
tpwright4423 wrote:
<style x:key="ICStyle" targettype="{x:Type ListViewItem}" xmlns:x="#unknown">
<setter property="Background" value="{Binding Converter={StaticResource BkgConverter}}" />
</style>
Here the binding will send the whole object (
PickListItem
) to the Convert function. Since it is object with will not notify as the change you done is on the properties. You are supposed to bind with Path. This is how you do.
<Style x:Key="ICStyle" TargetType="{x:Type ListViewItem}">
<Setter Property="Background">
<Setter.Value>
<MultiBinding Converter="{StaticResource BkgConverter}">
<Binding Path="QtyPicked" />
<Binding Path="QtyToPick" />
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
Since it is using
MultiBinding
you have to change your converter to
IMultiValueConverter
like this,
public class PickListItemBackgroundConverter : IMultiValueConverter
{
#region IMultiValueConverter Members
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (targetType != typeof(Brush))
{
throw new InvalidOperationException("The targetType must be a Brush object");
}
if (values.Length < 2)
{
throw new ArgumentOutOfRangeException();
}
int qtyPicked = 0;
int qtyToPick = 0;
int.TryParse(values[0].ToString(), out qtyPicked);
int.TryParse(values[1].ToString(), out qtyToPick);
Brush bBrush = Brushes.Transparent;
if (qtyPicked > 0)
{
bBrush = (qtyPicked < qtyToPick) ? Brushes.Yellow : bBrush = Brushes.LimeGreen;
}
return bBrush;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
#endregion
}
And you are done. :thumbsup:
Mark it as answer if it is helpful.