0

I have a DataRow. In this DataRow I have a column, Confirmed.

I have several values bound to this column like so :

<UserControl /*Stuff*/
    DataContext="{Binding Path=DataRow, Source={x:Static Main:Class.Instance}}"
    /*Stuff*/
    <SolidColorBrush Color="{Binding Path=[Confirmed], Converter={StaticResource BRLC}, FallbackValue=Gray, TargetNullValue=Gray}"/>
    /*More Stuff*/
</UserControl>

The Column uses a Byte type value and I am using (in this example) the following converter :

public class ByteRedLimeConverter : IValueConverter {
    public object Convert( object value, Type targetType, object parameter, CultureInfo culture ) {
        return ( ( byte )value == 1 ) ? Colors.Red : Colors.Lime;
    }

    public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture ) {
        throw new NotImplementedException( );
    }
}

I have a button which is supposed to change the state of the column to which the property is bound from 0 to 1 to 0 (Toggle it, basically) and then call the OnPropertyChanged method of my ViewModel :

btnToggleDataRow.Click += ( S, E ) => {
    Class.Instance.DataRow.SetField( "Confirmed", ( byte )(
        Class.Instance.DataRow.Field<byte>( "Confirmed" ) == 1 ? 0 : 1 ) );
    Class.Instance.OnPropertyChanged( "DataRow" );
};

I've watched the debugger go into the getter of the property, but there is no change in what I am seeing. I think this is because the DataRow itself isn't changing; just the value within it.

How can I force my binding to re-read the value within the data-row and propagate the changed value?

EDIT

Okay I was able to figure it out.

The first thing I needed to do was change the converters I was using to pass an actual solid color brush with the color I wanted rather than just to pass a Color.

Doing this allowed me to create a binding on the Brush-based properties.

Then I just had to call the .GetBindingExpression( ... ).UpdateTarget( ) function on the object I wanted to update with the property that had the binding.

A bit convoluted but the answer which directed me to where I needed to be I got from here.

Really this is mostly just a duplicate of that question and will probably be closed and/or deleted...

Community
  • 1
  • 1
Will
  • 3,413
  • 7
  • 50
  • 107
  • Did you try `OnPropertyChanged( "Confirmed" );` ? – H H Dec 26 '15 at 15:54
  • @HenkHolterman Yes. I tried "Confirmed", "[Confirmed]", and "DataRow[Confirmed]". – Will Dec 26 '15 at 16:02
  • Have u tried `{Binding Path=DataRow, Source={x:Static Main:Class.Instance}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}`? – k1ll3r8e Dec 26 '15 at 18:10
  • @k1ll3r8e No. The binding is unidirectional and the source is not supposed to change based on what happens to the target. This would not work. – Will Dec 26 '15 at 22:38

0 Answers0