一、需要的前提文件
从网上下载Emoji的表情包,当然是png的图片,因为WPF不支持彩色的Emoji,所以,做列表的时候,需要用图片。
随着压缩包一起的还有一个Emoji.xml文件,文件的层级结构如下
<array>
<dict>
<key></key>
<array>
<e></e>
<array>
</dict>
</array>
其实我们需要的知识<e></e>中间的内容。
nature 2600 2614 2601 26c4 1f319 26a1 1f300 1f30a 1f431 1f436 1f42d 1f439 1f430 1f43a 1f438 1f42f 1f428 1f43b 1f437 1f42e 1f417 1f435 1f412 1f434 1f40e 1f42b 1f411 1f418 1f40d 1f426 1f424 1f414 1f427 1f41b 1f419 1f420 1f41f 1f433 1f42c 1f490 1f338 1f337 1f340 1f339 1f33b 1f33a 1f341 1f343 1f342 1f334 1f335 1f33e 1f41a objects 1f38d 1f49d 1f38e 1f392 1f393 1f38f 1f386 1f387 1f390 1f391 1f383 1f47b 1f385 1f384 1f381 1f514 1f389 1f388 1f4bf 1f4c0 1f4f7 1f3a5 1f4bb 1f4fa 1f4f1 1f4e0 260e 1f4bd 1f4fc 1f50a 1f4e2 1f4e3 1f4fb 1f4e1 27bf 1f50d 1f513 1f512 1f511 2702 1f528 1f4a1 1f4f2 1f4e9 1f4eb 1f4ee 1f6c0 1f6bd 1f4ba 1f4b0 1f531 1f6ac 1f4a3 1f52b 1f48a 1f489 1f3c8 1f3c0 26bd 26be 1f3be 26f3 1f3b1 1f3ca 1f3c4 1f3bf 2660 2665 2663 2666 1f3c6 1f47e 1f3af 1f004 1f3ac 1f4dd 1f4d6 1f3a8 1f3a4 1f3a7 1f3ba 1f3b7 1f3b8 303d 1f45f 1f461 1f460 1f462 1f455 1f454 1f457 1f458 1f459 1f380 1f3a9 1f451 1f452 1f302 1f4bc 1f45c 1f484 1f48d 1f48e 2615 1f375 1f37a 1f37b 1f378 1f376 1f374 1f354 1f35f 1f35d 1f35b 1f371 1f363 1f359 1f358 1f35a 1f35c 1f372 1f35e 1f373 1f362 1f361 1f366 1f367 1f382 1f370 1f34e 1f34a 1f349 1f353 1f346 1f345 people 1f604 1f60a 1f603 263a 1f609 1f60d 1f618 1f61a 1f633 1f60c 1f601 1f61c 1f61d 1f612 1f60f 1f613 1f614 1f61e 1f616 1f625 1f630 1f628 1f623 1f622 1f62d 1f602 1f632 1f631 1f620 1f621 1f62a 1f637 1f47f 1f47d 1f49b 1f499 1f49c 1f497 1f49a 2764 1f494 1f493 1f498 2728 1f31f 1f4a2 2755 2754 1f4a4 1f4a8 1f4a6 1f3b6 1f3b5 1f525 1f4a9 1f44d 1f44e 1f44c 1f44a 270a 270c 1f44b 270b 1f450 1f446 1f447 1f449 1f448 1f64c 1f64f 261d 1f44f 1f4aa 1f6b6 1f3c3 1f46b 1f483 1f46f 1f646 1f645 1f481 1f647 1f48f 1f491 1f486 1f487 1f485 1f466 1f467 1f469 1f468 1f476 1f475 1f474 1f471 1f472 1f473 1f477 1f46e 1f47c 1f478 1f482 1f480 1f463 1f48b 1f444 1f442 1f440 1f443 places 1f3e0 1f3eb 1f3e2 1f3e3 1f3e5 1f3e6 1f3ea 1f3e9 1f3e8 1f492 26ea 1f3ec 1f307 1f306 1f3e7 1f3ef 1f3f0 26fa 1f3ed 1f5fc 1f5fb 1f304 1f305 1f303 1f5fd 1f308 1f3a1 26f2 1f3a2 1f6a2 1f6a4 26f5 2708 1f680 1f6b2 1f699 1f697 1f695 1f68c 1f693 1f692 1f691 1f69a 1f683 1f689 1f684 1f685 1f3ab 26fd 1f6a5 26a0 1f6a7 1f530 1f3b0 1f68f 1f488 2668 1f3c1 1f38c 1f1ef_1f1f5 1f1f0_1f1f7 1f1e8_1f1f3 1f1fa_1f1f8 1f1eb_1f1f7 1f1ea_1f1f8 1f1ee_1f1f9 1f1f7_1f1fa 1f1ec_1f1e7 1f1e9_1f1ea symbols 0031_20e3 0032_20e3 0033_20e3 0034_20e3 0035_20e3 0036_20e3 0037_20e3 0038_20e3 0039_20e3 0030_20e3 0023_20e3 2b06 2b07 2b05 27a1 2197 2196 2198 2199 25c0 25b6 23ea 23e9 1f197 1f195 1f51d 1f199 1f192 1f3a6 1f201 1f4f6 1f235 1f233 1f250 1f239 1f22f 1f23a 1f236 1f21a 1f237 1f238 1f202 1f6bb 1f6b9 1f6ba 1f6bc 1f6ad 1f17f 267f 1f687 1f6be 3299 3297 1f51e 1f194 2733 2734 1f49f 1f19a 1f4f3 1f4f4 1f4b9 1f4b1 2648 2649 264a 264b 264c 264d 264e 264f 2650 2651 2652 2653 26ce 1f52f 1f170 1f171 1f18e 1f17e 1f532 1f534 1f533 1f55b 1f550 1f551 1f552 1f553 1f554 1f555 1f556 1f557 1f558 1f559 1f55a 2b55 274c 00a9 00ae 2122
二、解析文件
xml文件其实就是对压缩包里的png图片的一个分组,既然知道是做这个用的,则可以进行读取xml,并获取列表内容。
获取内容之前,要先根据建立一个实体,实体的内容写了三个字段key,keyimg(内容的第一个Emoji),EmojiCode
public class emojiEntity { private string _key;//分组 private string _keyImg;//分组图像 private Dictionary_emojiCode = new Dictionary ();//emoji编码 /// /// 分组 /// public string Key { get { return _key; } set { _key = value; } } ////// emoji编码 /// public DictionaryEmojiCode { get { return _emojiCode; } set { _emojiCode = value; } } /// /// 分组图像 /// public string KeyImg { get { return _keyImg = EmojiCode.Values.First(); } } }
读取xml文件,并写入到List集合中
private ListemojiList = new List (); /// /// emoji集合 /// public ListEmojiList { get { return emojiList; } set { emojiList = value; } } /// /// 解析xml /// public void AnayXML() { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(Path.Combine(Environment.CurrentDirectory,@"Emoji.xml")); XmlNode root = xmlDoc.SelectSingleNode("array"); XmlNodeList nodeList = root.ChildNodes; foreach (XmlNode xn in nodeList) { XmlElement xe = (XmlElement)xn; XmlNodeList subList = xe.ChildNodes; emojiEntity entity = new emojiEntity(); foreach (XmlNode xmlNode in subList) { if (xmlNode.Name== "key") { entity.Key = xmlNode.InnerText; } if (xmlNode.Name== "array") { XmlElement lastXe = (XmlElement)xmlNode; foreach (XmlNode lastNode in lastXe) { if (lastNode.Name=="e") { entity.EmojiCode.Add(lastNode.InnerText,GetEmojiPath(lastNode.InnerText)); } } } } EmojiList.Add(entity); } } ////// 返回Emoji路径 /// /// ///private string GetEmojiPath(string name) { return "../image/"+"emoji_" + name + ".png"; }
三、写ListBox和TabControl样式
四、绑定数据
五、效果图