Exemplo n.º 1
0
        public static void InsertItemInItemsControl(ItemsControl itemsControl,
                                                    object itemToInsert,
                                                    int insertionIndex)
        {
            if (itemToInsert == null)
            {
                return;
            }

            var itemsSource = itemsControl.ItemsSource;

            if (itemsSource != null && itemToInsert is DynamicFormEditor)
            {
                var propertyName = ((itemToInsert as DynamicFormEditor).DataContext
                                    as DynamicFormListBoxContent).BindingPath;
                var collectionView = itemsControl.ItemsSource as CollectionView;

                if (collectionView != null)
                {
                    foreach (PropertyInformation item in collectionView)
                    {
                        if (item.Name == propertyName)
                        {
                            item.HasBeenUsed = true;
                            break;
                        }
                        collectionView.Refresh();
                    }
                }
            }
            else if (itemsSource == null && itemToInsert is PropertyInformation)
            {
                // this occurs when dragging from the left side field list
                // to the form fields listings
                itemsControl.Items.Insert(insertionIndex,
                                          UIHelpers.DynamicFormEditorFactory(itemToInsert as
                                                                             PropertyInformation));
            }
            else if (itemsSource == null && itemToInsert is DynamicFormEditor)
            {
                itemsControl.Items.Insert(insertionIndex,
                                          itemToInsert);
            }
        }