Last active
August 29, 2015 14:17
-
-
Save nickdarnell/69fa07d1d75d5ab81316 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static class FauxValueChangedEventManager | |
| { | |
| private delegate void OnValueChanged(object sender, EventArgs args); | |
| private delegate object GetItem(object indexer); | |
| private static object m_currentManager; | |
| private static MethodInfo m_onValueChanaged; | |
| private static MethodInfo m_getItem; | |
| static FauxValueChangedEventManager() | |
| { | |
| Type managerType = Type.GetType("MS.Internal.Data.ValueChangedEventManager, PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); | |
| PropertyInfo currentmanager = managerType.GetProperty("CurrentManager", | |
| BindingFlags.NonPublic | BindingFlags.Static); | |
| m_currentManager = currentmanager.GetValue(null, null); | |
| m_getItem = managerType.GetMethod("get_Item", | |
| BindingFlags.NonPublic | BindingFlags.Instance); | |
| Type valueChangedRecord = Type.GetType("MS.Internal.Data.ValueChangedEventManager+ValueChangedRecord, PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); | |
| m_onValueChanaged = valueChangedRecord.GetMethod("OnValueChanged", | |
| BindingFlags.NonPublic | BindingFlags.Instance); | |
| } | |
| public static void NotifyPropertyChanged(object sender, string propertyName) | |
| { | |
| HybridDictionary records = (HybridDictionary)m_getItem.Invoke( | |
| m_currentManager, new object[] { sender }); | |
| if (records != null) | |
| { | |
| var properties = TypeDescriptor.GetProperties(sender); | |
| var property = properties[propertyName]; | |
| var record = records[property]; | |
| if (record != null) | |
| { | |
| m_onValueChanaged.Invoke(record, new object[] { sender, null }); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment