Skip to content

WPF0014 should not warn here #292

@JohanLarsson

Description

@JohanLarsson
            var ints = new ObservableCollection<ObservableCollection<int>>
            {
                new ObservableCollection<int>(new[] { 1, 2 }),
                new ObservableCollection<int>(new[] { 3, 4 }),
                new ObservableCollection<int>(new[] { 5, 6 }),
            };
            var dataGrid = new DataGrid();
            dataGrid.SetValue(ItemsSource.RowsSourceProperty, ints);

And

    /// <summary>
    /// Attached properties for setting rows.
    /// </summary>
    public static partial class ItemsSource
    {
        /// <summary>
        /// An <see cref="IEnumerable"/> of rows where each row is an <see cref="IEnumerable"/> with the values.
        /// </summary>
        public static readonly DependencyProperty RowsSourceProperty = DependencyProperty.RegisterAttached(
            "RowsSource",
            typeof(IEnumerable),
            typeof(ItemsSource),
            new PropertyMetadata(
                default(IEnumerable),
                OnRowsSourceChanged),
            x => x is null || x is IEnumerable<IEnumerable>);

        /// <summary>Helper for setting <see cref="RowsSourceProperty"/> on <paramref name="element"/>.</summary>
        /// <param name="element"><see cref="DataGrid"/> to set <see cref="RowsSourceProperty"/> on.</param>
        /// <param name="value">RowsSource property value.</param>
        public static void SetRowsSource(this DataGrid element, IEnumerable? value)
        {
            if (element is null)
            {
                throw new System.ArgumentNullException(nameof(element));
            }

            element.SetValue(RowsSourceProperty, value);
        }

        /// <summary>Helper for getting <see cref="RowsSourceProperty"/> from <paramref name="element"/>.</summary>
        /// <param name="element"><see cref="DataGrid"/> to read <see cref="RowsSourceProperty"/> from.</param>
        /// <returns>RowsSource property value.</returns>
        [AttachedPropertyBrowsableForChildren(IncludeDescendants = false)]
        [AttachedPropertyBrowsableForType(typeof(DataGrid))]
        public static IEnumerable? GetRowsSource(this DataGrid element)
        {
            if (element is null)
            {
                throw new System.ArgumentNullException(nameof(element));
            }

            return (IEnumerable)element.GetValue(RowsSourceProperty);
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions