100125项目点滴(分组+标序号)

    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
posted @ 2010-01-25 16:25  紫色永恒  阅读(448)  评论(0编辑  收藏  举报