Background of Tab Control Header of index specified in view model turns a different colour

First time posting a question on here, so forgive me if I make any mistakes.

I have a counter called TurnNumber. This number changes dynamically, based on buttons at the top of the screen. I want to change the colour of the background of the tab whose index equals the TurnNumber.

This is what I have at the moment

MainWindowView:

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:DndBattleHelper"
        mc:Ignorable="d"
        Title="DnD Battle Helper" Height="450" Width="800"
        xmlns:VM="clr-namespace:DndBattleHelper.ViewModels"
        xmlns:Views="clr-namespace:DndBattleHelper.Views"
        xmlns:Converters="clr-namespace:DndBattleHelper.Views.Converters"
        Name="main">
    <Window.DataContext>
        <VM:MainWindowViewModel/>
    </Window.DataContext>
    <Window.Resources>
        <Converters:TwoEqualNumbersToBooleanConverter x:Key="TwoEqualNumbersToBooleanConverter" />
    </Window.Resources>
    
    <Grid>
        <StackPanel Orientation="Vertical">
            <StackPanel Orientation="Horizontal">
                <Button Content="Previous Turn" Command="{Binding PreviousTurnCommand}"/>
                <Button Content="Next Turn" Command="{Binding NextTurnCommand}"/>
            </StackPanel>
            <TabControl TabStripPlacement="Left" ItemsSource="{Binding EntitiesInInitiative}" SelectedIndex="{Binding SelectedTab}">
                <TabControl.Resources>
                    <Style TargetType="TabItem">
                        <Style.Triggers>
                            <DataTrigger Value="True">
                                <DataTrigger.Binding>
                                    <MultiBinding Converter="{StaticResource TwoEqualNumbersToBooleanConverter}" ConverterParameter="<">
                                        <Binding RelativeSource="{RelativeSource Self}" Path="(ItemsControl.AlternationIndex)" />
                                        <Binding Path="DataContext.TurnNumber" RelativeSource="{RelativeSource AncestorType=Window}" />
                                    </MultiBinding>
                                </DataTrigger.Binding>
                                <DataTrigger.Setters>
                                    <Setter Property="Background" Value="Red"/>
                                </DataTrigger.Setters>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>

                    <DataTemplate DataType="{x:Type VM:EnemyViewModel}">
                        <Views:EnemyView/>
                    </DataTemplate>
                    <DataTemplate DataType="{x:Type VM:PlayerViewModel}">
                        <Views:PlayerView/>
                    </DataTemplate>
                </TabControl.Resources>
                <TabControl.ItemTemplate>
                    <!-- this is the header template-->
                    <DataTemplate>
                        <TextBlock
                    Text="{Binding Name}" />
                    </DataTemplate>
                </TabControl.ItemTemplate>
            </TabControl>
        </StackPanel>
    </Grid>
</Window>

Converter:

    public class TwoEqualNumbersToBooleanConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (values.Length < 2)
                return false;

            int number1 = (int)values[0];
            int number2 = (int)values[1];

            // Return true if the tab index matches the TurnNumber
            return number1 == number2;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

TurnNumber is passed in correctly, and I trigger the converter each time it changes. Currently it appears that I am passing the wrong value for “Tab item index”, as I call the converter 3 times, but every time the value 0 is passed in. This means that when TurnNumber = 0, then the converter actually returns true:

When TurnNumber = 0

However, it changes all of the tab items to be red, rather than just the one whose index equals TurnNumber.

I would also like this to override SelectedTab colours, so that the selected tab is the standard grey, the TurnNumber tab is red, but if the TurnNumber Tab is also the Selected Tab, then it is Red. Currently Grey overrides the red.

Thank you!

New contributor

powpow is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật