Note that there are some explanatory texts on larger screens.

plurals
  1. POINotifyPropertyChanged does not update Value Converter
    primarykey
    data
    text
    <p>I have some properties which implement the <strong>INotifyPropertyChanged</strong> interface. It works fine. But in my code I also use some value converters (if value &lt; 3 - make grid red, if value >3 and value &lt; 10 - make grid blue, etc.).</p> <p>The problem is how to refresh value converter after <strong>PropertyChanged</strong> was raised? Is there simple code behind solution? Thanks all and sorry for my bad English!</p> <p>Here some code:</p> <pre><code>public class NotifyColors : INotifyPropertyChanged { private Color _TodayColor; public Color TodayColor { get { return _TodayColor; } set { if (_TodayColor != value) { _TodayColor = value; OnPropertyChanged("TodayColor"); } } } public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(String info) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(info)); // it raised correctly when I change color with color picker control } } } // here is value converter [ValueConversion(typeof(object), typeof(Brush))] public class PositionToBackgroundConverter : IValueConverter { ModulePreferences ModulePrefs; public PositionToBackgroundConverter(ModulePreferences ModulePrefs) { this.ModulePrefs = ModulePrefs; } #region IValueConverter Member public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (ModulePrefs.UseColoringByPosition) { try { if (value != null) { short value_short = (short)value; if (value_short &lt;= 3) return (Brush)new SolidColorBrush(ModulePrefs.NotifyColorsObj._TodayColor); // here is changing property else return (Brush)new SolidColorBrush(ModulePrefs.NotifyColorsObj.T100PlusColor); } else return Brushes.Transparent; } catch { return Brushes.Transparent; } } else return Brushes.Transparent; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return null; } #endregion } </code></pre> <p>And here I apply my value converter to the grid:</p> <pre><code>// assign backgroundconverter var grid = new FrameworkElementFactory(typeof(Grid)); bin = new Binding(); bin.Path = new PropertyPath(string.Format("DataItem.{0}", LastPositionColumnName)); bin.Converter = new PositionToBackgroundConverter(ProjectViewObj.ModulePrefs); grid.SetValue(Grid.BackgroundProperty, bin); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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