Lazy load data bound list inside TabControl WPF
I have a TabControl with three tabs, each containing a DataGrid bound to a list of data. The model behind the view is setup with lazy loaded properties.
<TabControl>
<TabItem>
<DataGrid ItemsSource="{Bindin开发者_C百科g FirstList}" >
<DataGrid.Columns>
<DataGridTextColumn Header="Column1" Binding="{Binding Property1}" />
<DataGridTextColumn Header="Column2" Binding="{Binding Property2}" />
</DataGrid.Columns>
</DataGrid>
</TabItem>
<TabItem>
<DataGrid ItemsSource="{Binding SecondList}" >
<DataGrid.Columns>
<DataGridTextColumn Header="Column1" Binding="{Binding Property1}" />
<DataGridTextColumn Header="Column2" Binding="{Binding Property2}" />
</DataGrid.Columns>
</DataGrid>
</TabItem>
<TabItem>
<DataGrid ItemsSource="{Binding ThirdList}" >
<DataGrid.Columns>
<DataGridTextColumn Header="Column1" Binding="{Binding Property1}" />
<DataGridTextColumn Header="Column2" Binding="{Binding Property2}" />
</DataGrid.Columns>
</DataGrid>
</TabItem>
</TabControl>
My intention was that each list should be loaded only when clicking on the relevant tab. However, I end up loading all lists initially.
Is there any way to lazy load bindings for each TabItem?
Thanks!
I had that problem, too, and ended up adding a "Loaded" Property to the datasources that i bound to the IsSelected
property of the TabItems, and that way lazy-loaded the data. Thinking about it, maybe using Datatemplates would have worked, too.
精彩评论