diff --git a/ValidCode.Netcore/Repro/Issue292.cs b/ValidCode.Netcore/Repro/Issue292.cs new file mode 100644 index 00000000..a557c8d1 --- /dev/null +++ b/ValidCode.Netcore/Repro/Issue292.cs @@ -0,0 +1,68 @@ +namespace ValidCode.Repro +{ + using System.Collections; + using System.Collections.ObjectModel; + using System.Windows; + using System.Windows.Controls; + + public static class Issue292 + { + /// + /// An of rows where each row is an with the values. + /// + public static readonly DependencyProperty EnumerableProperty = DependencyProperty.RegisterAttached( + "Enumerable", + typeof(IEnumerable), + typeof(Issue292), + new PropertyMetadata(default(IEnumerable))); + + /// Helper for setting on . + /// to set on. + /// RowsSource property value. + public static void SetEnumerable(this DataGrid element, IEnumerable? value) + { + if (element is null) + { + throw new System.ArgumentNullException(nameof(element)); + } + + element.SetValue(EnumerableProperty, value); + } + + /// Helper for getting from . + /// to read from. + /// RowsSource property value. + [AttachedPropertyBrowsableForChildren(IncludeDescendants = false)] + [AttachedPropertyBrowsableForType(typeof(DataGrid))] + public static IEnumerable? GetEnumerable(this DataGrid element) + { + if (element is null) + { + throw new System.ArgumentNullException(nameof(element)); + } + + return (IEnumerable)element.GetValue(EnumerableProperty); + } + + public static DataGrid M1() + { + var dataGrid = new DataGrid(); + var xs = new ObservableCollection(new[] { 1, 2 }); + dataGrid.SetValue(Issue292.EnumerableProperty, xs); + return dataGrid; + } + + public static DataGrid M2() + { + var dataGrid = new DataGrid(); + var xs = new ObservableCollection> + { + new ObservableCollection(new[] { 1, 2 }), + new ObservableCollection(new[] { 3, 4 }), + new ObservableCollection(new[] { 5, 6 }), + }; + dataGrid.SetValue(Issue292.EnumerableProperty, xs); + return dataGrid; + } + } +}