internal static bool TryGetDetailColumnName(DataGridItemPropertyMap itemPropertyMap, string masterColumnName, out string detailColumnName)
        {
            detailColumnName = default(string);

            if (itemPropertyMap == null)
            {
                return(false);
            }

            var masterItemProperty = ItemsSourceHelper.GetItemPropertyFromProperty(itemPropertyMap.MasterItemProperties, masterColumnName);

            if (masterItemProperty == null)
            {
                return(false);
            }

            DataGridItemPropertyBase detailItemProperty;

            if (!itemPropertyMap.TryGetDetailItemProperty(masterItemProperty, out detailItemProperty))
            {
                return(false);
            }

            detailColumnName = PropertyRouteParser.Parse(detailItemProperty);

            return(!string.IsNullOrEmpty(detailColumnName));
        }
        internal void SetContext(DataGridCollectionView collectionView)
        {
            if (collectionView == null)
            {
                m_contextProperty = null;
            }
            else
            {
                var propertyName = m_propertyGroupDescription.PropertyName;

                if (string.IsNullOrEmpty(propertyName))
                {
                    m_contextProperty = null;
                }
                else
                {
                    m_contextProperty = ItemsSourceHelper.GetItemPropertyFromProperty(collectionView.ItemProperties, propertyName);
                }
            }
        }
            private void ExportDataItemCore(DataGridContext dataGridContext, ClipboardExporterBase clipboardExporter, int itemIndex, object item,
                                            int[] exportedVisiblePositions, ColumnBase[] columnsByVisiblePosition)
            {
                var dataGridCollectionViewBase = dataGridContext.ItemsSourceCollection as DataGridCollectionViewBase;

                clipboardExporter.StartDataItem(dataGridContext, item);

                // Ensure the count does not exceeds the columns count
                var exportedVisiblePositionsCount = exportedVisiblePositions.Length;

                exportedVisiblePositionsCount = Math.Min(exportedVisiblePositionsCount, columnsByVisiblePosition.Length);

                var intersectedIndexes = this.GetIntersectedRangesForIndex(dataGridContext, itemIndex, exportedVisiblePositions, exportedVisiblePositionsCount);

                for (int i = 0; i < exportedVisiblePositionsCount; i++)
                {
                    var fieldValue      = default(object);
                    var column          = default(Column);
                    var visiblePosition = exportedVisiblePositions[i];

                    // Export null if not intersected by a SelectionRange
                    if (intersectedIndexes.Contains(visiblePosition))
                    {
                        // Only export visible data column
                        column = columnsByVisiblePosition[visiblePosition] as Column;

                        if (column == null)
                        {
                            continue;
                        }

                        // Use DataGridCollectionView directly since the DataGridItemProperty uses PropertyDescriptor which increase the read of the field value
                        var dataGridItemProperty = default(DataGridItemPropertyBase);

                        // Try to get a DataGridItemProperty matching the column FieldName and get the value from it
                        if (dataGridCollectionViewBase != null)
                        {
                            dataGridItemProperty = ItemsSourceHelper.GetItemPropertyFromProperty(dataGridCollectionViewBase.ItemProperties, column.FieldName);

                            if (dataGridItemProperty != null)
                            {
                                fieldValue = ItemsSourceHelper.GetValueFromItemProperty(dataGridItemProperty, item);
                            }
                        }

                        // If none was found, create a BindingPathValueExtractor from this column
                        if ((dataGridCollectionViewBase == null) || (dataGridItemProperty == null))
                        {
                            // We don't have a DataGridCollectionView, use a BindingPathValueExtractor to create a binding to help us get the value for the Column in the data item
                            var extractorForRead = default(BindingPathValueExtractor);

                            if (m_columnToBindingPathExtractor.TryGetValue(column, out extractorForRead) == false)
                            {
                                extractorForRead = dataGridContext.GetBindingPathExtractorForColumn(column, item);
                                m_columnToBindingPathExtractor.Add(column, extractorForRead);
                            }

                            fieldValue = extractorForRead.GetValueFromItem(item);
                        }
                    }

                    if (fieldValue != null)
                    {
                        //Verify if the value should be converted to the displayed value for exporting.
                        var foreignKeyConfiguration = column.ForeignKeyConfiguration;
                        if (foreignKeyConfiguration != null && foreignKeyConfiguration.UseDisplayedValueWhenExporting)
                        {
                            fieldValue = foreignKeyConfiguration.GetDisplayMemberValue(fieldValue);
                        }
                        else
                        {
                            var valueConverter = column.DisplayedValueConverter;
                            if (valueConverter != null)
                            {
                                fieldValue = valueConverter.Convert(fieldValue, typeof(object), column.DisplayedValueConverterParameter,
                                                                    column.GetCulture(column.DisplayedValueConverterCulture));
                            }
                            else
                            {
                                var valueFormat = column.CellContentStringFormat;
                                if (!string.IsNullOrEmpty(valueFormat))
                                {
                                    fieldValue = string.Format(column.GetCulture(), valueFormat, fieldValue);
                                }
                            }
                        }
                    }

                    clipboardExporter.StartDataItemField(dataGridContext, column, fieldValue);
                    clipboardExporter.EndDataItemField(dataGridContext, column, fieldValue);
                }

                clipboardExporter.EndDataItem(dataGridContext, item);
            }
        public int Compare(RawItem xRawItem, RawItem yRawItem)
        {
            if (xRawItem == null)
            {
                return((yRawItem == null) ? 0 : -1);
            }

            if (yRawItem == null)
            {
                return(1);
            }

            var lastSortDirection    = ListSortDirection.Ascending;
            var sortDescriptions     = m_collectionView.SortDescriptions;
            var sortDescriptionCount = sortDescriptions.Count;

            if (sortDescriptionCount > 0)
            {
                var result         = default(int);
                var itemProperties = m_collectionView.ItemProperties;

                for (int i = 0; i < sortDescriptionCount; i++)
                {
                    var sortDescription = sortDescriptions[i];
                    lastSortDirection = sortDescription.Direction;

                    var itemProperty = ItemsSourceHelper.GetItemPropertyFromProperty(itemProperties, sortDescription.PropertyName);
                    if (itemProperty == null)
                    {
                        continue;
                    }

                    var supportInitialize = itemProperty as ISupportInitialize;
                    var xData             = default(object);
                    var yData             = default(object);

                    if (supportInitialize != null)
                    {
                        supportInitialize.BeginInit();
                    }

                    try
                    {
                        xData = ItemsSourceHelper.GetValueFromItemProperty(itemProperty, xRawItem.DataItem);
                        yData = ItemsSourceHelper.GetValueFromItemProperty(itemProperty, yRawItem.DataItem);

                        if (itemProperty.IsSortingOnForeignKeyDescription)
                        {
                            var foreignKeyDescription = itemProperty.ForeignKeyDescription;

                            xData = foreignKeyDescription.GetDisplayValue(xData);
                            yData = foreignKeyDescription.GetDisplayValue(yData);
                        }
                    }
                    finally
                    {
                        if (supportInitialize != null)
                        {
                            supportInitialize.EndInit();
                        }
                    }

                    var sortComparer = itemProperty.SortComparer;

                    if (sortComparer != null)
                    {
                        result = sortComparer.Compare(xData, yData);
                    }
                    else
                    {
                        result = ObjectDataStore.CompareData(xData, yData);
                    }

                    if (result != 0)
                    {
                        if (lastSortDirection == ListSortDirection.Descending)
                        {
                            return(-result);
                        }

                        return(result);
                    }
                }
            }

            if (lastSortDirection == ListSortDirection.Descending)
            {
                return(yRawItem.Index - xRawItem.Index);
            }

            return(xRawItem.Index - yRawItem.Index);
        }