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>
作者:紫色永恒
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利