Exemple #1
0
        public OptionColumnInfo(DataGridColumn column, Type boundObjectType, JibGrid grid)
        {
            if (column == null)
            {
                return;
            }

            Column = column;
            var boundColumn = column as DataGridBoundColumn;

            if (boundColumn != null)
            {
                System.Windows.Data.Binding binding = boundColumn.Binding as System.Windows.Data.Binding;
                if (binding != null && !string.IsNullOrWhiteSpace(binding.Path.Path))
                {
                    System.Reflection.PropertyInfo propInfo = null;
                    //if (boundColumn.Binding != null)
                    //    propInfo = boundColumn.Binding.GetType().GetProperty("Source");
                    if (boundObjectType != null)
                    {
                        propInfo = boundObjectType.GetType().GetProperty(binding.Path.Path);
                    }

                    if (propInfo == null && grid.HasItems)
                    {
                        if (grid.SourceType == null)
                        {
                            grid.SourceType = grid.Items.CurrentItem.GetType();
                        }
                        propInfo = grid.SourceType.GetProperty(binding.Path.Path);
                    }

                    //propInfo = boundObjectType.GetType().GetProperties().FirstOrDefault();
                    //if (propInfo == null) propInfo = boundObjectType.GetProperty("FullName");

                    if (propInfo != null)
                    {
                        IsValid              = true;
                        PropertyPath         = binding.Path.Path;
                        PropertyType         = propInfo != null ? propInfo.PropertyType : typeof(string);
                        Converter            = binding.Converter;
                        ConverterCultureInfo = binding.ConverterCulture;
                        ConverterParameter   = binding.ConverterParameter;
                    }
                    else
                    {
                        if (System.Diagnostics.Debugger.IsAttached && System.Diagnostics.Debugger.IsLogging())
                        {
                            System.Diagnostics.Debug.WriteLine("Jib.WPF.Controls.DataGrid.JibGrid: BindingExpression path error: '{0}' property not found on '{1}'", binding.Path.Path, boundObjectType.ToString());
                        }
                    }
                }
            }
            else if (column.SortMemberPath != null && column.SortMemberPath.Length > 0)
            {
                PropertyPath = column.SortMemberPath;
                PropertyType = boundObjectType.GetProperty(column.SortMemberPath).PropertyType;
            }
        }
        public static void OnFilteredItemsSourceChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            JibGrid g = sender as JibGrid;

            if (g != null)
            {
                var list = (IEnumerable)e.NewValue;
                var view = new CollectionViewSource();
                view.Source = list;
                Type srcT = e.NewValue.GetType().GetInterfaces().First(i => i.Name.StartsWith("IEnumerable"));
                g.FilterType  = srcT.GetGenericArguments().First();
                g.ItemsSource = CollectionViewSource.GetDefaultView(list);
                if (g.Filters != null)
                {
                    foreach (var filter in g.Filters)
                    {
                        filter.ResetControl();
                    }
                }
            }
        }