MaterialDesignInXAML / MaterialDesignInXamlToolkit

Google's Material Design in XAML & WPF, for C# & VB.Net.
http://materialdesigninxaml.net
MIT License
15.06k stars 3.41k forks source link

Initial foreground of Icon in TabItem Header #3670

Open corvinsz opened 1 week ago

corvinsz commented 1 week ago

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 commented 6 days ago

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>
danaildinev commented 5 hours ago

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>