/// <summary>
        /// 下移
        /// </summary>
        private void TreeViewOneLevelMenuItemDownMe_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 > 6)
            {
                return;
            }

            //与上方交换索引
            NodeX1 nodex1Tmp = new NodeX1();

            nodex1Tmp.ItemStartValue = m_NodeX0.NodeX1s[indexX1].ItemStartValue;
            nodex1Tmp.ItemEndValue   = m_NodeX0.NodeX1s[indexX1].ItemEndValue;
            nodex1Tmp.NodeX2s        = m_NodeX0.NodeX1s[indexX1].NodeX2s;

            m_NodeX0.NodeX1s[indexX1].ItemStartValue = m_NodeX0.NodeX1s[indexX1 + 1].ItemStartValue;
            m_NodeX0.NodeX1s[indexX1].ItemEndValue   = m_NodeX0.NodeX1s[indexX1 + 1].ItemEndValue;
            m_NodeX0.NodeX1s[indexX1].NodeX2s        = m_NodeX0.NodeX1s[indexX1 + 1].NodeX2s;

            m_NodeX0.NodeX1s[indexX1 + 1].ItemStartValue = nodex1Tmp.ItemStartValue;
            m_NodeX0.NodeX1s[indexX1 + 1].ItemEndValue   = nodex1Tmp.ItemEndValue;
            m_NodeX0.NodeX1s[indexX1 + 1].NodeX2s        = nodex1Tmp.NodeX2s;
        }
        /// <summary>
        /// 标题菜单新增字节
        /// </summary>
        private void TitleMenuItem_Click(object sender, RoutedEventArgs e)
        {
            MenuItem mi     = sender as MenuItem;
            int      length = Convert.ToInt32(mi.Tag);

            if (length == 99)
            {
                for (int i = 0; i < m_NodeX0.NodeX1s.Count; i++)
                {
                    m_NodeX0.NodeX1s[i].IsExpanded = true;
                }
                return;
            }

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

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

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

            lastEndIndex += 1;

            NodeX1 nodex1 = new NodeX1();

            nodex1.StartByteSources = nodex1.EndByteSources = new string[] { "0", "1", "2", "3", "4", "5", "6", "7" };
            nodex1.ItemStartValue   = lastEndIndex;
            nodex1.ItemEndValue     = lastEndIndex + length - 1;


            m_NodeX0.NodeX1s.Add(nodex1);
        }
        //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;
                    }
                }
            }
        }