private static void OnRowChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
    {
        // When the Key changes, try to find the data row that has the new key.
        // If it is not found, return null.
        DataTableDictionary <T> dataTableDictionary = sender as DataTableDictionary <T>;

        if (dataTableDictionary.m_isBeingChanged)
        {
            return;                                            //Avoid Reentry
        }
        dataTableDictionary.m_isBeingChanged = true;
        try
        {
            if (dataTableDictionary.Row == null)
            {
                dataTableDictionary.Key = null;
            }
            else
            {
                dataTableDictionary.Key = dataTableDictionary.Row[dataTableDictionary.indexKeyField];
            }
        }
        catch (Exception ex)
        {
            throw new Exception("Unknow error in DataTableDictionary.OnRowChanged.", ex);
        }
        finally
        {
            dataTableDictionary.m_isBeingChanged = false;
        }
    }
    private static void OnKeyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
    {
        // When the Key changes, try to find the data row that has the new key.
        // If it is not found, return null.
        DataTableDictionary <T> dataTableDictionary = sender as DataTableDictionary <T>;

        if (dataTableDictionary.m_isBeingChanged)
        {
            return;                                            //Avoid Reentry
        }
        dataTableDictionary.m_isBeingChanged = true;
        try
        {
            if (dataTableDictionary.IndexedView == null)      //We had to defer loading.
            {
                if (!dataTableDictionary.ConstructDictionary())
                {
                    return;     //throw new Exception("Dataview is null. Check to make sure that all Reference tables are loaded.");
                }
            }
            DataRowView[] result = _IndexedView.FindRows(dataTableDictionary.Key);
            DataRowView dataRow  = result.Length > 0 ? result[0] : null;
            //Sometimes a null key is valid - but sometimes it's just xceed being dumb - so we only skip the following step if it wasn't xceed.
            if (dataRow == null && dataTableDictionary.Key != null)
            {
                //The entry was not in the DataView, so we will add it to the underlying table so that it is not nullified. Treaty validation will take care of notifying the user.
                DataRow newRow = _SourceList.NewRow();
                //DataRowView newRow = _IndexedView.AddNew();
                int keyIndex = _SourceList.Columns.IndexOf(dataTableDictionary.indexKeyField);
                for (int i = 0; i < _SourceList.Columns.Count; i++)
                {
                    if (i == keyIndex)
                    {
                        newRow[i] = dataTableDictionary.Key;
                    }
                    else if (_SourceList.Columns[i].DataType == typeof(String))
                    {
                        newRow[i] = "(Unrecognized Code: '" + (dataTableDictionary.Key == null ? "NULL" : dataTableDictionary.Key) + "')";
                    }
                }
                newRow.EndEdit();
                _SourceList.Rows.InsertAt(newRow, 0);
                dataRow = _IndexedView.FindRows(dataTableDictionary.Key)[0];
            }
            dataTableDictionary.Row = dataRow;
        }
        catch (Exception ex)
        {
            throw new Exception("Unknow error in DataTableDictionary.OnKeyChanged.", ex);
        }
        finally
        {
            dataTableDictionary.m_isBeingChanged = false;
        }
    }