Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPF0014 should not warn here #292

Open
JohanLarsson opened this issue Jan 2, 2021 · 0 comments
Open

WPF0014 should not warn here #292

JohanLarsson opened this issue Jan 2, 2021 · 0 comments

Comments

@JohanLarsson
Copy link
Collaborator

            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);
        }
JohanLarsson added a commit that referenced this issue Jan 2, 2021
JohanLarsson added a commit that referenced this issue Jan 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant