MaterialDesignInXamlToolkit icon indicating copy to clipboard operation
MaterialDesignInXamlToolkit copied to clipboard

Initial foreground of Icon in TabItem Header

Open corvinsz opened this issue 1 year ago • 2 comments

Bug explanation

When using a PackIcon inside of the header of a TabItem, the PackIcons foreground is initially not set correctly. Once you switch the tabs the foreground fixes itself (notice how the color of the Icon in the first tab changes from white to green): TabItemForegroundBug

Here is a repo that showcases this bug.

Version

5.1.0

corvinsz avatar Sep 12 '24 15:09 corvinsz

I noticed when setting the Style of the TabControl explicitly, the icon has the correct foreground: image

<StackPanel VerticalAlignment="Center">
    <TabControl HorizontalAlignment="Center">
        <TabItem>
            <TabItem.Header>
                <StackPanel Orientation="Horizontal">
                    <materialDesign:PackIcon Kind="Bin" />
                    <TextBlock Text="Tab 1" />
                </StackPanel>
            </TabItem.Header>
            <TextBlock Text="Content 1" />
        </TabItem>
    </TabControl>

    <TabControl Margin="0,30,0,0"
                HorizontalAlignment="Center"
                Style="{StaticResource MaterialDesignTabControl}">
        <TabItem>
            <TabItem.Header>
                <StackPanel Orientation="Horizontal">
                    <materialDesign:PackIcon Kind="Bin" />
                    <TextBlock Text="Tab 2" />
                </StackPanel>
            </TabItem.Header>
            <TextBlock Text="Content 2" />
        </TabItem>
    </TabControl>
</StackPanel>

corvinsz avatar Sep 18 '24 16:09 corvinsz

Another fix (hack) I found several months ago was setting the foreground of the icon from the textblock foreground in the tabitem header textblock.

<TabItem.Header>
    <StackPanel Orientation="Horizontal">
        <md:PackIcon Kind="Album"
                     Foreground="{Binding Foreground, ElementName=tabTbAlbums}"/>
        <TextBlock x:Name="tabTbAlbums"
            Text="{DynamicResource stringAlbums}"/>
    </StackPanel>
</TabItem.Header>

danaildinev avatar Sep 24 '24 22:09 danaildinev