//string m_XmlDir = "UserDifinedProtocol";


        public void LoadXml(string filePath, ref List <NodeX0> sendNodeX0s, ref List <NodeX0> recNodeX0s)
        {
            xml.Load(filePath);

            XmlElement xRoot = xml.DocumentElement; //根元素,"用户自定义协议版本"

            if (xRoot != null)
            {
                //帧数量
                XmlNodeList x0Nlist = xRoot.ChildNodes;  //发送帧或者接收帧

                foreach (XmlElement eCur0 in x0Nlist)
                {
                    List <NodeX0> tmpNodeX0s = new List <NodeX0>();
                    XmlNodeList   x00Nlist   = eCur0.ChildNodes; //多个帧节点,"发送帧1","发送帧2","发送帧3"。。。
                    foreach (XmlElement eCur00 in x00Nlist)      //每个帧的内容,"Title","CANID"。。。
                    {
                        NodeX0 nodeX0 = new NodeX0();
                        foreach (XmlNode eCur01 in eCur00.ChildNodes) //0级节点封装节点,每一个都是一帧
                        {
                            switch (eCur01.Name)
                            {
                            case "Title":
                                nodeX0.Title = eCur01.InnerText;     //要读取节点的属性
                                break;

                            case "CANID":
                                nodeX0.UINTCANID = SpecialFunctions.HexStringToUint(eCur01.InnerText);
                                break;

                            case "NodeX1":
                            {
                                #region 一级节点

                                foreach (XmlNode eCur10 in eCur01.ChildNodes)         //1级节点内所有内容遍历
                                {
                                    NodeX1 nodeX1 = new NodeX1();
                                    nodeX1.StartByteSources = nodeX1.EndByteSources = new string[] { "0", "1", "2", "3", "4", "5", "6", "7" };
                                    XmlNodeList eCur10List = eCur10.ChildNodes;
                                    foreach (XmlNode eCur1 in eCur10List)
                                    {
                                        switch (eCur1.Name)
                                        {
                                        case "ItemStartValue":
                                            nodeX1.ItemStartValue = Convert.ToInt32(eCur1.InnerText);             //要读取节点的属性
                                            break;

                                        case "ItemEndValue":
                                            nodeX1.ItemEndValue = Convert.ToInt32(eCur1.InnerText);
                                            break;

                                        case "NodeX2":
                                        {
                                            #region 二级节点

                                            foreach (XmlNode eCur20 in eCur1.ChildNodes)                 //1级节点内所有内容遍历
                                            {
                                                XmlNodeList eCur20List     = eCur20.ChildNodes;
                                                NodeX2      nodeX2         = new NodeX2();
                                                string[]    bitIndexSource = null;
                                                switch (nodeX1.ItemLengthValue)
                                                {
                                                case 1:
                                                    bitIndexSource = new string[] { "0", "1", "2", "3", "4", "5", "6", "7" };
                                                    break;

                                                case 2:
                                                    bitIndexSource = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" };
                                                    break;

                                                case 3:
                                                    bitIndexSource = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15",
                                                                                    "16", "17", "18", "19", "20", "21", "22", "23" };
                                                    break;

                                                case 4:
                                                    bitIndexSource = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15",
                                                                                    "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" };
                                                    break;

                                                default: break;
                                                }
                                                nodeX2.StartBitSources = nodeX2.EndBitSources = bitIndexSource;
                                                //nodeX2.StartBitSources = nodeX2.EndBitSources = new string[] { "0", "1", "2", "3", "4", "5", "6", "7" };
                                                nodeX2.Value = 0;


                                                foreach (XmlNode eCur2 in eCur20List)
                                                {
                                                    string a = eCur2.ParentNode.Name;

                                                    switch (eCur2.Name)
                                                    {
                                                    case "StartIndex":
                                                        nodeX2.StartBitIndex = Convert.ToInt32(eCur2.InnerText);                     //要读取节点的属性
                                                        break;

                                                    case "EndIndex":
                                                        nodeX2.EndBitIndex = Convert.ToInt32(eCur2.InnerText);
                                                        break;

                                                    case "Resolution":
                                                        nodeX2.Resolution = Convert.ToDouble(eCur2.InnerText);
                                                        break;

                                                    case "Offset":
                                                        nodeX2.Offset = Convert.ToDouble(eCur2.InnerText);
                                                        break;

                                                    case "ValueName":
                                                        nodeX2.ValueName = eCur2.InnerText;

                                                        break;

                                                    case "Value":
                                                        nodeX2.Value = Convert.ToInt32(eCur2.InnerText);

                                                        break;

                                                    default: break;
                                                    }
                                                }
                                                nodeX1.NodeX2s.Add(nodeX2);
                                            }

                                            #endregion
                                        }
                                        break;

                                        default: break;
                                        }
                                    }
                                    nodeX0.NodeX1s.Add(nodeX1);
                                }
                                #endregion
                            }
                            break;

                            default: break;
                            }
                        }
                        tmpNodeX0s.Add(nodeX0);
                    }

                    if (eCur0.Name == "SendRoot")
                    {
                        sendNodeX0s = tmpNodeX0s;
                    }
                    else
                    {
                        recNodeX0s = tmpNodeX0s;
                    }
                }
            }
        }
        /// <summary>
        /// 新增位二级节点
        /// </summary>
        private void TreeViewOneLevelMenuItemAddChild_Click(object sender, RoutedEventArgs e)
        {
            //获取到对应的TreeViewItem
            var node    = ((TreeView)((System.Windows.Controls.Primitives.Popup)((ContextMenu)((MenuItem)sender).Parent).Parent).PlacementTarget) as TreeView;
            int indexX1 = -1;

            if (node == null)
            {
                return;
            }

            for (int i = 0; i < node.Items.Count; i++)
            {
                if (node.Items[i] == node.SelectedItem)
                {
                    indexX1 = i;
                }
            }
            if (indexX1 == -1)
            {
                return;
            }



            //前一个结束索引索引
            int lastEndIndex = -1;

            if (m_NodeX0.NodeX1s[indexX1].NodeX2s.Count > 0)
            {
                lastEndIndex = m_NodeX0.NodeX1s[indexX1].NodeX2s[m_NodeX0.NodeX1s[indexX1].NodeX2s.Count - 1].EndBitIndex;
            }

            if (lastEndIndex + 1 > 7)
            {
                return;
            }

            lastEndIndex += 1;

            NodeX2 nodex2 = new NodeX2();

            string[] bitIndexSource = null;
            switch (m_NodeX0.NodeX1s[indexX1].ItemLengthValue)
            {
            case 1:
                bitIndexSource = new string[] { "0", "1", "2", "3", "4", "5", "6", "7" };
                break;

            case 2:
                bitIndexSource = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" };
                break;

            case 3:
                bitIndexSource = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15",
                                                "16", "17", "18", "19", "20", "21", "22", "23" };
                break;

            case 4:
                bitIndexSource = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15",
                                                "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" };
                break;

            default: break;
            }
            nodex2.StartBitSources = nodex2.EndBitSources = bitIndexSource;
            nodex2.StartBitIndex   = lastEndIndex;
            nodex2.EndBitIndex     = lastEndIndex;
            nodex2.Resolution      = 1;
            nodex2.Offset          = 0;
            nodex2.ValueName       = "名称";
            nodex2.Value           = 0;

            m_NodeX0.NodeX1s[indexX1].NodeX2s.Add(nodex2);
        }