024hi
    public class TabItemInfo {
        public string Header { get; set; }
        public Color Color { get; set; }
    }
void MainPage_Loaded(object sender, RoutedEventArgs e) {
    var tabList = new List<TabItemInfo>() { 
        new TabItemInfo() { Header= "A" , Color = Colors.Red},
        new TabItemInfo() { Header= "B" , Color = Colors.Green},
        new TabItemInfo() { Header= "B" ,  Color = Colors.Green},
        new TabItemInfo() { Header= "A" , Color = Colors.Red},
        new TabItemInfo() { Header= "A" , Color = Colors.Red},
        new TabItemInfo() { Header= "C" , Color = Colors.Blue},
        new TabItemInfo() { Header= "A" ,Color = Colors.Red},
        new TabItemInfo() { Header= "B" ,Color = Colors.Green}
    };

    var dict = new Dictionary<string, int>();
    for (int i = 0; i < tabList.Count; i++) {
        if (!dict.Keys.Contains(tabList[i].Header)) {
            dict.Add(tabList[i].Header, 1);
            tabList[i].Header = string.Concat(tabList[i].Header, "(", 1, ")");
        }
        else {
            int max = dict[tabList[i].Header];
            dict[tabList[i].Header] = ++max;
            tabList[i].Header = string.Concat(tabList[i].Header, "(", max, ")");
        }
    }

    foreach (var tab in tabList) {
        tabControl1.Items.Add(
            new TabItem() { Header = tab.Header, Background = new SolidColorBrush(tab.Color) });
    }

}
    <Grid x:Name="LayoutRoot">
        <controls:TabControl x:Name="tabControl1">
            
        </controls:TabControl>
    </Grid>
image

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-01-31
  • 2022-02-25
  • 2021-10-04
猜你喜欢
  • 2021-11-11
  • 2022-01-30
  • 2021-09-20
  • 2022-12-23
  • 2021-06-09
  • 2021-09-15
  • 2021-10-22
相关资源
相似解决方案