Not using Fody, trouble with INPC

Sep 10, 2012 at 9:53 PM

I have a toy project I implemented using Fody to do code weaving for INPC (similar to the PropertyTools Property Control examples). It works fine. But because of configuration management issues with Fody I need to do the INPC by hand. It doesn't appear to be working and I'm wondering what I'm missing.

Here's a code snippet showing what I'm doing

public sealed class LisSerialPortSettings : INotifyPropertyChanged, IDataErrorInfo
	{
		public LisSerialPortSettings() {}

		private bool _serialEnabled;
		public bool SerialEnabled
		{
			get { return _serialEnabled; }
			set { if (value == _serialEnabled) return; _serialEnabled = value; OnPropertyChanged("SerialEnabled"); }
		}

		private string _portName;
		[VisibleBy("IsSerialEnabled")] 
		public string PortName
		{
			get { return _portName; }
			set { if (value == _portName) return; _portName = value; OnPropertyChanged("PortName"); }
		}

		[Browsable(false)]
		public bool IsSerialEnabled
		{
			get { return SerialEnabled; }
		}

		public event PropertyChangedEventHandler PropertyChanged;

		public void OnPropertyChanged(string propertyName)
		{
			var handler = PropertyChanged;
			if (handler != null)
				handler(this, new PropertyChangedEventArgs(propertyName));
		}
	}
I can see a handler is getting called by setting a break on the call to handler at
the end of the code snippet. But the visibility of PortName is not being changed.

Any clues to what I might be missing?

Coordinator
Sep 11, 2012 at 4:22 AM

I would try to raise the NPC event on IsSerialEnabled:

		public bool SerialEnabled
		{
			get { return _serialEnabled; }
			set { if (value == _serialEnabled) return; _serialEnabled = value; OnPropertyChanged("SerialEnabled"); 
OnPropertyChanged("IsSerialEnabled"); }
		}
Sep 11, 2012 at 2:39 PM

Good catch! That does the trick. Thanks.

I'm glad it was kind of subtle. :-)