I have a class as follows
public partial class Configuration : INotifyPropertyChanged
{
private bool _isToolTips;
public bool IsToolTips
{
get { return _isToolTips; }
set { Set(this, "IsToolTips", ref _isToolTips, value, PropertyChanged); }
}
#region INotifyPropertyChanged functionality
public static void Set<T>(object owner, string propName, ref T oldValue, T newValue,
PropertyChangedEventHandler eventHandler)
{
// make sure the property name really exists
if (owner.GetType().GetProperty(propName) == null)
{
throw new ArgumentException("No property named ‘" +
propName + "‘ on " + owner.GetType().FullName);
}
// we only raise an event if the value has changed
if (Equals(oldValue, newValue)) return;
oldValue = newValue;
if (eventHandler != null)
{
eventHandler(owner, new PropertyChangedEventArgs(propName));
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void notifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
#endregion INotifyPropertyChanged functionality
}
This class is compiled in a separate assembly. I then add it to my MainWindow constructor as follows [edit]
public MainWindow()
{
initializeAttributes();
InitializeComponent();
CurrentConfig = new Configuration
{
IsToolTips = true
};
DataContext = CurrentConfig;
composeModules();
}
[end edit]
and in my XMAL I have this [edit]
<MenuItem Name="ToolTips"
Header="Tool Tips"
IsCheckable="True"
IsChecked="{Binding Source=CurrentConfig,
Path=IsToolTips,
Mode=TwoWay}"
Click="onToolTipsClick">
</MenuItem>
[end edit]
The problem is that the “PropertyChanged” member of my Configuration class is always set to null. Where am I going wrong?
Source=CurrentConfigurationsets theSourceto the string"CurrentConfiguration", which obviously won’t have that property.Debug your binding and see the references if you don’t know enough about them.