You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Setting the DataGrid.ItemsSource to an enumerable/collection doesnt show the rows of items.
Only the columns are generated, if AutoGenerateColumns has not been set to false.
Steps to Reproduce
Steps to reproduce the behavior:
Add a DataGrid to a page
Databind OR Set ItemsSource directly from code behind
Windows 10 Build Number:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [ ] May 2019 Update (18362)
- [ ] Insider Build (build number: )
App min and target version:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [ ] May 2019 Update (18362)
- [ ] Insider Build (xxxxx)
Device form factor:
- [x] macOS
- [x] WASM
- [ ] iOS (?: not tested)
- [ ] Android (?: not tested)
- [ ] UWP
Visual Studio
- [ ] 2017 (version: )
- [x] 2019 (version: )
- [ ] 2019 Preview (version: )
Additional context
note: If you attach the assignment to a button handler. Tapping a first time will make the columns to be generated, and tapping it again will cause the rows to be shown.
workaround:
publicstaticclassDataGridExtensions{
#region Property: DelayedItemsSource
publicstaticDependencyPropertyDelayedItemsSourceProperty{get;}=DependencyProperty.RegisterAttached("DelayedItemsSource",typeof(IEnumerable),typeof(DataGridExtensions),newPropertyMetadata(default,(d,e)=>d.Maybe<DataGrid>(control =>OnDelayedItemsSourceChanged(control,e))));publicstaticIEnumerableGetDelayedItemsSource(DataGridobj)=>(IEnumerable)obj.GetValue(DelayedItemsSourceProperty);publicstaticvoidSetDelayedItemsSource(DataGridobj,IEnumerablevalue)=>obj.SetValue(DelayedItemsSourceProperty,value);
#endregion
privatestaticvoidOnDelayedItemsSourceChanged(DataGridsender,DependencyPropertyChangedEventArgse){// DataGrid not showing rows with initial values, only "late" provided values are displayed somehow...// This is the workaround for that:_=RunOnUIThread(()=>sender.ItemsSource=(IEnumerable)e.NewValue);}privatestaticasyncTaskRunOnUIThread(Actionaction){awaitCoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,()=>{action();});}}
for databinding, just bind to that attached property instead of ItemsSource.
for code-behind, just call SetDelayedItemsSource during OnLoaded like so:
Describe the bug
Setting the
DataGrid.ItemsSource
to an enumerable/collection doesnt show the rows of items.Only the columns are generated, if
AutoGenerateColumns
has not been set to false.Steps to Reproduce
Steps to reproduce the behavior:
Expected behavior
The data to be displayed.
Screenshots
n/a
Environment
NuGet Package(s):
Additional context
note: If you attach the assignment to a button handler. Tapping a first time will make the columns to be generated, and tapping it again will cause the rows to be shown.
workaround:
for databinding, just bind to that attached property instead of
ItemsSource
.for code-behind, just call
SetDelayedItemsSource
duringOnLoaded
like so:The text was updated successfully, but these errors were encountered: