有关Menu的绑定。
假设有一个Node类,如下:
- public class Node
- {
- public string Name { get; set; }
- public List<Node> Children { get; set; }
- public override string ToString()
- {
- return Name;
- }
- }
复制代码
C1Menu的绑定代码参考:
- public MainPage()
- {
- InitializeComponent();
- _menu.ItemsSource = GenerateData();
- }
- private IList GenerateData()
- {
- int firstLevel = 3;
- int secondLevel = 3;
- int thirdLevel = 3;
- List<Node> firstLevelNodes = new List<Node>(firstLevel);
- for (int i = 0; i < firstLevel; i++)
- {
- Node flNode = new Node();
- flNode.Name = string.Format("Node_{0}", i);
- flNode.Children = new List<Node>(secondLevel);
- for (int j = 0; j < secondLevel; j++)
- {
- Node slNode = new Node();
- slNode.Name = string.Format("Node_{0}.{1}", i, j);
- slNode.Children = new List<Node>(thirdLevel);
- for (int k = 0; k < thirdLevel; k++)
- {
- Node tlNode = new Node();
- tlNode.Name = string.Format("Node_{0}.{1}.{2}", i, j, k);
- tlNode.Children = new List<Node>(thirdLevel);
- slNode.Children.Add(tlNode);
- }
- flNode.Children.Add(slNode);
- }
- firstLevelNodes.Add(flNode);
- }
- return firstLevelNodes;
- }
复制代码
如果您的需求有差别,您可以以附件或是图片的形式将您的需求发给我们(如何贴图之前已经发给您,发不了的具体错误是什么?提示了错误还是有什么)
否则很抱歉,我无法想象您的需求。 |