Beispiel #1
0
        private void LoadPropertyObjects()
        {
            List <PropertyInfo> propertiesList = new List <PropertyInfo>(this.ClassObjectType.GetProperties());

            foreach (PropertyInfo inf in propertiesList)
            {
                if (this.LoadOnlyAttributedFields)
                {
                    object fieldValues = inf.GetCustomAttribute(typeof(FieldInformationAttribute));

                    if (fieldValues == null)
                    {
                        continue;
                    }
                }

                ModelViewItem viewItem = this.CreateField(this.ClassObjectType.Name, this.ClassObject, inf);

                viewItem.ModelViewItemGotFocus += this.ModelItem_Focus;

                this.Items.Add(viewItem);
            }

            foreach (ModelViewItem child in this.Items.OrderBy(s => s.Sort))
            {
                this.uxContent.Children.Add(child);
            }

            if (this.Items.Count > 0)
            {
                ((ModelViewItem)this.uxContent.Children[0]).Focus();
            }
        }
 private void ModelItem_Focus(ModelViewItem sender, object focusedbject)
 {
     if (this.ModelViewItemGotFocus != null)
     {
         this.ModelViewItemGotFocus(sender, focusedbject);
     }
 }
        private void AddItem(object item)
        {
            Type itemType = item.GetType();

            TreeViewItemTool headerItem = this.CreateHeader(itemType);

            List <PropertyInfo> propertiesList = new List <PropertyInfo>(itemType.GetProperties());

            List <ModelViewItem> itemsList = new List <ModelViewItem>();

            double maxCaptionWidth = 100;

            foreach (PropertyInfo inf in propertiesList)
            {
                double itemWidth = 0;

                ModelViewItem viewItem = this.CreateField(headerItem.Tag.ToString(), item, inf, out itemWidth);

                if (!viewItem.HasFieldInformation && this.LoadOnlyAttributedFields)
                {
                    continue;
                }

                viewItem.ModelViewItemGotFocus += this.ModelItem_Focus;

                itemsList.Add(viewItem);

                if (itemWidth > maxCaptionWidth)
                {
                    maxCaptionWidth = itemWidth;
                }
            }

            int itemIndex = 0;

            foreach (ModelViewItem modelItem in itemsList.OrderBy(i => i.Sort))
            {
                modelItem.CaptionWidth = maxCaptionWidth;

                string itemKey = $"{headerItem.Tag}:{modelItem.PropertyName}";

                itemsDesiredIndexDic.Add(itemKey, itemIndex);

                this.CreateVisibilityMenuItem(modelItem, itemKey.ToString());

                itemIndex++;

                if (modelItem.Visibility != Visibility.Visible)
                {
                    this.hidenItemsDict.Add(itemKey, modelItem.PropertyInfo);

                    continue;
                }

                headerItem.Items.Add(modelItem);
            }

            base.Items.Add(headerItem);
        }
        private void LoadPropertyObjects()
        {
            List <PropertyInfo> propertiesList = new List <PropertyInfo>(this.ClassObjectType.GetProperties());

            foreach (PropertyInfo inf in propertiesList)
            {
                if (this.LoadOnlyAttributedFields)
                {
                    object fieldValues = inf.GetCustomAttribute(typeof(FieldInformationAttribute));

                    if (fieldValues == null)
                    {
                        continue;
                    }
                }

                ModelViewItem viewItem = this.CreateField(this.ClassObjectType.Name, this.ClassObject, inf);

                viewItem.ModelViewItemGotFocus += this.ModelItem_Focus;

                this.Items.Add(viewItem);
            }

            if (this.Items.Any(eit => !eit.EitherOrGroupName.IsNullEmptyOrWhiteSpace()))
            {
                Dictionary <string, List <ModelViewItem> > eitherOrItems = this.Items
                                                                           .Where(weo => !weo.EitherOrGroupName.IsNullEmptyOrWhiteSpace())
                                                                           .GroupBy(eon => eon.EitherOrGroupName)
                                                                           .ToDictionary(eod => eod.Key, eod => eod.ToList());

                foreach (KeyValuePair <string, List <ModelViewItem> > groupKey in eitherOrItems)
                {
                    if (groupKey.Key.IsNullEmptyOrWhiteSpace())
                    {
                        continue;
                    }

                    foreach (ModelViewItem item in groupKey.Value)
                    {
                        item.Binding.ValidationRules.Add(new IsEitherOrValudationRule
                        {
                            IsRequired = true,
                            GroupItems = groupKey.Value
                        });
                    }
                }
            }

            foreach (ModelViewItem child in this.Items.OrderBy(s => s.Sort))
            {
                this.uxContent.Children.Add(child);
            }

            if (this.Items.Count > 0)
            {
                ((ModelViewItem)this.uxContent.Children[0]).Focus();
            }
        }
        private ModelViewItem CreateField(string parentTypeName, object parentObject, PropertyInfo property)
        {
            ModelViewItem result = null;

            result = new ModelViewItem(parentTypeName, parentObject, property);

            result.ModelViewItemBrowse += this.ModelViewItem_Browse;

            return(result);
        }
        private ModelViewItem CreateField(string parentTypeName, object parentObject, PropertyInfo property, out double captionWidth)
        {
            ModelViewItem result = null;

            result = new ModelViewItem(parentTypeName, parentObject, property);

            captionWidth = result.CaptionTextWidth;

            return(result);
        }
        private void CreateVisibilityMenuItem(ModelViewItem propertyItem, string parentName)
        {
            MenuItem visibilityMenuItem = new MenuItem
            {
                IsCheckable = true,
                IsChecked   = propertyItem.Visibility == Visibility.Visible ? true : false,
                Header      = propertyItem.Caption,
                Tag         = parentName
            };

            visibilityMenuItem.Checked += this.VisibilityItem_Checked;

            visibilityMenuItem.Unchecked += this.VisibilityItem_Checked;

            this.ContextMenu.Items.Add(visibilityMenuItem);
        }
Beispiel #8
0
        public ModelViewItem this[string caption]
        {
            get
            {
                foreach (ModelViewObject child in this.Children)
                {
                    ModelViewItem result = child[caption];

                    if (result != null)
                    {
                        return(result);
                    }
                }

                return(null);
            }
        }
Beispiel #9
0
        public ModelViewItem this[int classObjectIndex, string caption]
        {
            get
            {
                ModelViewObject child = (ModelViewObject)this.Children[classObjectIndex];

                if (child == null)
                {
                    return(null);
                }

                ModelViewItem result = child[caption];

                if (result != null)
                {
                    return(result);
                }

                return(null);
            }
        }
Beispiel #10
0
        private void ModelItem_Focus(ModelViewItem sender, object focusedbject)
        {
            this.SelectedModelItem = sender;

            this.SelectedItem = focusedbject;
        }
        private void VisibilityItem_Checked(object sender, RoutedEventArgs e)
        { // We need to do this as the Visibility set leaves a gap as big as the one in my teeth
            MenuItem item = (MenuItem)sender;

            if (item.IsChecked)
            {
                string itemKey = item.Tag.ToString();

                string[] itemKeysArray = itemKey.Split(new char[] { ':' });

                PropertyInfo propertyItem = this.hidenItemsDict[itemKey];

                int desiredIndex = itemsDesiredIndexDic[itemKey];

                int parentIndex = 0;

                TreeViewItemTool parent = this.FindParentItem(itemKeysArray[0], out parentIndex);

                ModelViewItem modelItem = new ModelViewItem(parent.Tag.ToString(), this.Items[parentIndex], propertyItem);

                if (parent.Items.Count == 0)
                {
                    this.hidenItemsDict.Remove(itemKey);

                    parent.Items.Add(modelItem);

                    return;
                }

                modelItem.ModelViewItemGotFocus += this.ModelItem_Focus;

                string checkItemKey = $"{((ModelViewItem)parent.Items[0]).ParentObjectTypeName}:{((ModelViewItem)parent.Items[0]).PropertyName}";

                int itemsCollectionIndex = itemsDesiredIndexDic[checkItemKey];

                int insertAt = 0;

                while (itemsCollectionIndex < desiredIndex)
                {
                    insertAt++;

                    if (insertAt >= parent.Items.Count)
                    {
                        break;
                    }

                    checkItemKey = $"{((ModelViewItem)parent.Items[insertAt]).ParentObjectTypeName}:{((ModelViewItem)parent.Items[insertAt]).PropertyName}";

                    itemsCollectionIndex = itemsDesiredIndexDic[checkItemKey];
                }

                modelItem.Visibility = Visibility.Visible;

                this.hidenItemsDict.Remove(itemKey);

                parent.Items.Insert(insertAt, modelItem);
            }
            else
            {
                int parentIndex = -1;

                string itemKey = item.Tag.ToString();

                ModelViewItem propertyItem = this.FindItem(itemKey, out parentIndex);

                propertyItem.ModelViewItemGotFocus -= this.ModelItem_Focus;

                TreeViewItemTool parent = ((TreeViewItemTool)base.Items[parentIndex]);

                this.hidenItemsDict.Add(itemKey, propertyItem.PropertyInfo);

                parent.Items.Remove(propertyItem);
            }

            this.RefreshcaptionWidths();
        }