コード例 #1
0
        private void setContentType(ContentType contentType)
        {
            IServiceManager serviceManager = ServiceManagerFactory.GetServiceManager(_siteSetting.SiteSettingType);

            string[] folderFieldInLimitedView = new string[] { "FileLeafRef" };

            double height = 10;

            fieldRequiredPresnet = false;
            FieldMappingsStackPanel.Children.Clear();

            //Get default mappings
            ItemPropertyMappings itemPropertyMappings = null;

            if (_folderSettings != null)
            {
                itemPropertyMappings = _folderSettings.GetItemPropertyMappings(contentType.ID);
            }

            List <Field> filtredField = contentType.Fields;

            if (_siteSetting.limitFolderEditableProperties & isFolder)
            {
                filtredField = contentType.Fields.Where(f => folderFieldInLimitedView.Contains(f.Name)).ToList();
            }

            foreach (Field field in filtredField)
            {
                if (!_displayFileName && field.Name == "FileLeafRef")
                {
                    continue;
                }

                Label label = new Label()
                {
                    Content = field.DisplayName.removeTextInsideParenthesis()
                };


                label.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                label.VerticalAlignment   = System.Windows.VerticalAlignment.Top;
                if (field.Required && !field.ReadOnly)
                {
                    label.Foreground     = new SolidColorBrush(Colors.Red);
                    label.Content       += "*";
                    fieldRequiredPresnet = true;
                }

                label.Margin = new Thickness(0, height, 5, 0);
                FieldMappingsStackPanel.Children.Add(label);

                //if (field.ReadOnly == false)
                //{
                EditItemControl editItemControl = EditItemManager.GetEditItemControl(_webURL, field, null, contentType, _siteSetting, _rootFolder);

                editItemControl.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                editItemControl.VerticalAlignment   = System.Windows.VerticalAlignment.Top;
                editItemControl.Margin = new Thickness(160, height, 0, 0);//



                FieldMappingsStackPanel.Children.Add(editItemControl);
                if (_properties != null && _properties.Count > 0)
                {
                    //Set default mapping value
                    ApplicationItemProperty defaultApplicationItemProperty = null;
                    if (itemPropertyMappings != null)
                    {
                        ItemPropertyMapping mapping = itemPropertyMappings.Where(m => m.ServicePropertyName == field.Name).FirstOrDefault();
                        if (mapping != null)
                        {
                            defaultApplicationItemProperty = _properties.Where(p => p.Name == mapping.ApplicationPropertyName).FirstOrDefault();
                            editItemControl.IsEnabled      = false;
                        }
                        else
                        {
                            mapping = _defaultFolderSetting.ItemPropertyMappings.Where(m => m.ServicePropertyName == field.Name).FirstOrDefault();
                            if (mapping != null)
                            {
                                defaultApplicationItemProperty = _properties.Where(p => p.Name == mapping.ApplicationPropertyName).FirstOrDefault();
                                editItemControl.IsEnabled      = false;
                            }
                        }
                    }

                    EditItems.FieldMappingControl fieldMappingControl = new EditItems.FieldMappingControl(_properties, field, defaultApplicationItemProperty);
                    fieldMappingControl.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                    fieldMappingControl.VerticalAlignment   = System.Windows.VerticalAlignment.Top;
                    fieldMappingControl.Margin = new Thickness(350, height, 0, 0);

                    FieldMappingsStackPanel.Children.Add(fieldMappingControl);
                }

                height = height + editItemControl.GetHeight() + 5;

                if (_defaultValues != null)
                {
                    object[] args = { serviceManager, field, editItemControl };
                    Dispatcher.BeginInvoke(new setDefaultValuesDelegate(setDefaultValues), args);
                }


                //}
            }

            labelfieldRequired.Visibility = fieldRequiredPresnet ? Visibility.Visible : Visibility.Hidden;
        }