コード例 #1
0
        private static IList <IDataFieldInfo> GetDescriptionsForItemType(Type dataType)
        {
            var infos = new List <IDataFieldInfo>();

            Queue <Type> typesToReflect = new Queue <Type>();

            typesToReflect.Enqueue(dataType);

            while (typesToReflect.Count > 0)
            {
                var      currentType = typesToReflect.Dequeue();
                TypeInfo typeInfo    = currentType.GetTypeInfo();
                if (typeInfo.IsInterface)
                {
                    foreach (Type interfaceType in typeInfo.ImplementedInterfaces)
                    {
                        typesToReflect.Enqueue(interfaceType);
                    }
                }

                var props = currentType.GetRuntimeProperties().Where(pi => pi.GetMethod != null && !pi.GetIndexParameters().Any() && pi.GetMethod.IsPublic && !pi.GetMethod.IsStatic && pi.GetCustomAttribute <SkipAutoGenerateAttribute>() == null);
                foreach (var propertyInfo in props)
                {
                    var propertyAccess = BindingExpressionHelper.CreateGetValueFunc(currentType, propertyInfo.Name);
                    var propertySetter = BindingExpressionHelper.CreateSetValueAction(currentType, propertyInfo.Name);
                    var newInfo        = new PropertyInfoFieldInfo(propertyInfo, propertyAccess, propertySetter, currentType);
                    newInfo.Role = FieldInfoHelper.GetRoleForType(propertyInfo.PropertyType);
                    infos.Add(newInfo);
                }
            }

            return(infos);
        }
コード例 #2
0
        public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)
        {
            //Border cellElement = new Border();
            //  var valueBinding = new System.Windows.Data.Binding(this.DataMemberBinding.Path.Path)
            //{
            //    Mode = BindingMode.OneTime,
            //    Converter = new ColorToBrushConverter()
            //};
            //cellElement.SetBinding(Border.BackgroundProperty, valueBinding);
            //cellElement.Width = 45;
            //cellElement.Height = 20;
            //cellElement.CornerRadius = new CornerRadius(5);
            var         cellElement        = new TextBlock();
            IEnumerable displayItemsSource = null;

            if (ItemsSourceBinding != null)
            {
                displayItemsSource = BindingExpressionHelper.GetValue(dataItem, ItemsSourceBinding) as IEnumerable;
            }
            else
            {
                displayItemsSource = ItemsSource;
            }
            var value = GetPropertyValue(displayItemsSource, cell.DataContext);

            if (value != null)
            {
                cellElement.Text = value.ToString();
            }
            else
            {
                cellElement.Text = "";
            }
            return(cellElement);
        }
コード例 #3
0
        /// <inheritdoc/>
        internal override void PrepareEditorContentVisual(FrameworkElement editorContent, Binding binding)
        {
            var item = binding.Source;

            var itemsSourceBinding = new Binding();

            if (!string.IsNullOrEmpty(this.ItemsSourcePath))
            {
                itemsSourceBinding.Source = item;
                itemsSourceBinding.Path   = new PropertyPath(this.ItemsSourcePath);
            }
            else
            {
                itemsSourceBinding.Path   = new PropertyPath("ItemsSource");
                itemsSourceBinding.Source = this;
            }

            var displayMemberPathBinding = new Binding
            {
                Path   = new PropertyPath("DisplayMemberPath"),
                Source = this
            };

            var selectedValuePathBinding = new Binding
            {
                Path   = new PropertyPath("SelectedValuePath"),
                Source = this
            };

            editorContent.SetBinding(ComboBox.ItemsSourceProperty, itemsSourceBinding);
            editorContent.SetBinding(ComboBox.DisplayMemberPathProperty, displayMemberPathBinding);
            editorContent.SetBinding(ComboBox.SelectedValuePathProperty, selectedValuePathBinding);

            if (!string.IsNullOrEmpty(this.SelectedValuePath))
            {
                var source = (editorContent as ComboBox).ItemsSource as IEnumerable <object>;

                if (source.Any())
                {
                    var comboBoxValueGetter = BindingExpressionHelper.CreateGetValueFunc(source.First().GetType(), this.SelectedValuePath);
                    var selectedItem        = source.FirstOrDefault(x =>
                    {
                        var selectedItemValue = comboBoxValueGetter(x)?.Equals(this.GetValueForInstance(item));

                        return(selectedItemValue ?? false);
                    });

                    (editorContent as ComboBox).SelectedItem = selectedItem;
                    editorContent.SetBinding(ComboBox.SelectedValueProperty, binding);
                }
            }
            else
            {
                editorContent.SetBinding(ComboBox.SelectedItemProperty, binding);
            }
        }
コード例 #4
0
        private static void OnDisplayMemberPathChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var column = d as DataGridComboBoxColumn;

            if (column.itemsType != null)
            {
                column.itemPropertyGetter = BindingExpressionHelper.CreateGetValueFunc(column.itemsType, (string)e.NewValue);
                column.OnProperyChange(UpdateFlags.All);
            }
        }
コード例 #5
0
        public override FrameworkElement CreateCellEditElement(GridViewCell cell, object dataItem)
        {
            var cellEditElement = new MyStaticLookup();

            cellEditElement.NewItemEnabled  = NewItemEnabled;
            cellEditElement.EditItemEnabled = EditItemEnabled;

            cellEditElement.DisplayMember       = this.DisplayMemberPath;
            cellEditElement.SelectedValueMember = this.SelectedValueMemberPath;

            IList itemsSource = null;

            if (ItemsSourceBinding != null)
            {
                itemsSource = BindingExpressionHelper.GetValue(dataItem, ItemsSourceBinding) as IList;
            }
            else
            {
                itemsSource = ItemsSource as IList;
            }

            cellEditElement.ItemsSource       = itemsSource as IList;
            cellEditElement.SelectionChanged += (sender, e) => CellEditElement_SelectionChanged(sender, e, cell.DataContext);
            cellEditElement.EditItemClicked  += (sender, e) => CellEditElement_EditItemClicked(sender, e, dataItem);
            //cellEditElement.Width = this.ActualWidth;
            cellEditElement.HorizontalAlignment = HorizontalAlignment.Stretch;

            if (cell.DataContext != null)
            {
                var property = cell.DataContext.GetType().GetProperty(this.DataMemberBinding.Path.Path);
                if (property != null)
                {
                    var bindvalue = property.GetValue(cell.DataContext);
                    internalChange = true;
                    cellEditElement.SelectedValue = bindvalue;
                    internalChange = false;
                }
            }

            //this.BindingTarget = RadColorPicker.SelectedColorProperty;

            //System.Windows.Data.Binding valueBinding = this.CreateValueBinding();
            //cellEditElement.SetBinding(RadColorPicker.SelectedColorProperty, valueBinding);
            return(cellEditElement as FrameworkElement);
        }
コード例 #6
0
        /// <inheritdoc/>
        public object GetDisplayValueForInstance(object instance)
        {
            var item = this.GetValueForInstance(instance);

            if (string.IsNullOrEmpty(this.SelectedValuePath))
            {
                var type = item.GetType();
                if (this.itemPropertyGetter == null)
                {
                    // TODO: does not work for dynamic objects
                    this.itemsType          = type;
                    this.itemPropertyGetter = BindingExpressionHelper.CreateGetValueFunc(this.itemsType, this.DisplayMemberPath);
                }

                return(this.itemPropertyGetter(item));
            }

            return(item);
        }
コード例 #7
0
        private Func <object, object> GetPropertyAccess(string propertyName)
        {
            var propertyAcces = BindingExpressionHelper.CreateGetValueFunc(typeof(Order), propertyName);

            return(propertyAcces);
        }