コード例 #1
0
ファイル: innerlistcolumn.cs プロジェクト: 40a/PowerShell
        /// <summary>
        /// Initializes a new instance of <see cref="InnerListColumn"/> class with the specified data description and visibility.
        /// </summary>
        /// <param name="dataDescription">The description of the data this column is bound to.</param>
        /// <param name="isVisible">Whether the column is initially visible.</param>
        /// <param name="createDefaultBinding">Whether the column should create a default binding using the specified data's property.</param>
        public InnerListColumn(UIPropertyGroupDescription dataDescription, bool isVisible, bool createDefaultBinding)
        {
            if (dataDescription == null)
            {
                throw new ArgumentNullException("dataDescription");
            }

            GridViewColumnHeader header = new GridViewColumnHeader();
            header.Content = dataDescription.DisplayContent;
            header.DataContext = this;

            Binding automationNameBinding = new Binding("DataDescription.DisplayName");
            automationNameBinding.Source = this;
            header.SetBinding(AutomationProperties.NameProperty, automationNameBinding);

            this.Visible = isVisible;
            this.Header = header;
            this.DataDescription = dataDescription;

            if (createDefaultBinding)
            {
                var defaultBinding = new Binding(GraphicalHostReflectionWrapper.EscapeBinding(dataDescription.PropertyName));
                defaultBinding.StringFormat = GetDefaultStringFormat(dataDescription.DataType);
                defaultBinding.ConverterCulture = CultureInfo.CurrentCulture;

                this.DisplayMemberBinding = defaultBinding;
            }
        }
コード例 #2
0
        /// <summary>
        /// Called when the ItemsSource changes to auto populate the GridView columns
        /// with reflection information on the first element of the ItemsSource.
        /// </summary>
        /// <param name="newValue">
        /// The new ItemsSource. 
        /// This is used just to fetch .the first collection element.
        /// </param>
        internal void PopulateColumns(System.Collections.IEnumerable newValue)
        {                      
            if (newValue == null)
            {
                return; // No elements, so we can't populate
            }

            IEnumerator newValueEnumerator = newValue.GetEnumerator();
            if (!newValueEnumerator.MoveNext())
            {
                return; // No first element, so we can't populate
            }

            object first = newValueEnumerator.Current;
            if (first == null)
            {
                return;
            }
            
            Debug.Assert(this.AvailableColumns.Count == 0, "AvailabeColumns should be empty at this point");

            PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(first);
            foreach (PropertyDescriptor property in properties)
            {
                UIPropertyGroupDescription dataDescription = new UIPropertyGroupDescription(property.Name, property.Name, property.PropertyType);
                InnerListColumn column = new InnerListColumn(dataDescription);
                this.AvailableColumns.Add(column);
            }
        }
コード例 #3
0
ファイル: innerlistcolumn.cs プロジェクト: 40a/PowerShell
 /// <summary>
 /// Initializes a new instance of <see cref="InnerListColumn"/> class with the specified data description and visibility, and creates a simple binding to its property.
 /// </summary>
 /// <param name="dataDescription">The property description for this column's data.</param>
 /// <param name="isVisible">Whether the column is initially visible.</param>
 public InnerListColumn(UIPropertyGroupDescription dataDescription, bool isVisible)
     : this(dataDescription, isVisible, true)
 {
     // This constructor just calls another constructor to create a column with a simple binding.
 }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of <see cref="InnerListColumn"/> class with the specified data description, and creates a simple binding to its property.
 /// The column will be initially visible by default.
 /// </summary>
 /// <param name="dataDescription">The property description for this column's data.</param>
 public InnerListColumn(UIPropertyGroupDescription dataDescription)
     : this(dataDescription, true, true)
 {
     // This constructor just calls another constructor to create a visible column with a simple binding.
 }