Search code examples
wpfcustom-controlsprogress-bartabitem

Embedding a ProgressBar in the TabItem header in WPF


The project I am working on generates a series of tabs for each item opened by the user. For some tabs in particular, certain database hits and calculations take an extended period of time. I was trying to determine a simple way to alert the user when the tab is ready and figured a progress bar would be as good or better than other ways I considered.

I am wondering if there is a way to embed a progress bar behind the header text of a TabItem or if I will need to build my own CustomControl. I have no clue how to do either, however, I think some examples of the latter exist in the project so I could try to figure that out through them.


Solution

  • You can define the layout of a TabItem pretty easily. This snippet of XAML will create a TabControl with one TabItem where the header of the TabItem has a ProgressBar with a TextBlock over the ProgressBar.

    Of course, please customize this XAML to actually make it look good :-D

    <TabControl>
        <TabItem>
            <TabItem.Header>
                <Grid>
                    <ProgressBar Width="100" />
                    <TextBlock Text="Some Tab"/>
                </Grid>
            </TabItem.Header>
        </TabItem>
    </TabControl>