2
votes

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="{Binding 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!

1

1 Answers

0
votes

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.