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...