public List<TextBlock> Items
        {
            get
            {
                List<TextBlock> results = new List<TextBlock>();
                foreach (FontFamily family in Fonts.SystemFontFamilies)
                {
                    foreach (KeyValuePair<XmlLanguage, string> pair in family.FamilyNames)
                    {
                        TextBlock t = new TextBlock();                        t.Text = pair.Value;
                        t.FontFamily = family;
                        t.FontSize = 12;                        results.Add(t);
                    }
                }
                return results;
            }
        }

解决方案 »

  1.   


            public List<TextBlock> Items
            {
                get
                {
                    List<TextBlock> results = new List<TextBlock>();
                    Fonts.SystemFontFamilies.ToList().ForEach(family => family.FamilyNames.ToList().ForEach(pair => results.Add(new TextBlock 
                    { 
                        Text = pair.Value, 
                        FontFamily = family,
                        FontSize = 12 
                    })));
                    return results;
                }
            }
      

  2.   

    精简一下:        public List<TextBlock> Items
            {
                get
                {
                    List<TextBlock> results = Fonts.SystemFontFamilies.SelectMany(family => family.FamilyNames.Select(pair => new TextBlock { Text = pair.Value, FontFamily = family, FontSize = 12 })).ToList();
                    return results;
                }
            }