コード例 #1
0
            //结束位
            private static void OnTreeViewItemEndByteChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
                int b = Convert.ToInt32(e.NewValue);

                if (b < 0 || b > 7)
                {
                    return;
                }

                UserTreeViewItem1 gauge = d as UserTreeViewItem1;

                //Label lb = gauge.GetTemplateChild("feL1") as Label;
                //Label lb = gauge.Template.FindName("feL1",gauge) as Label;
                //lb.Content = "byte " + gauge.TreeViewItemStartByte.ToString() + ":" + e.NewValue.ToString();

                gauge.Header = "byte " + gauge.TreeViewItemStartByte.ToString() + ":" + e.NewValue.ToString();
                //长度
                gauge.SetValue(TreeViewItemByteLengthProperty, gauge.TreeViewItemEndByte - gauge.TreeViewItemStartByte);
            }
コード例 #2
0
        /// <summary>
        /// 根节点右键菜单点击,新增一级节点,一个字节的节点
        /// </summary>
        private void TreeViewAddOneByteChild_Click(object sender, RoutedEventArgs e)
        {
            UserTreeViewItem1 tviTmp = new UserTreeViewItem1();
            int lastEndIndex         = -1;

            if (myTreeView.Items.Count > 0)
            {
                lastEndIndex = ((UserTreeViewItem1)myTreeView.Items[myTreeView.Items.Count - 1]).TreeViewItemEndByte;
            }
            if (lastEndIndex >= 7)
            {
                return;
            }
            tviTmp.TreeViewItemStartByte = lastEndIndex + 1;
            tviTmp.TreeViewItemEndByte   = lastEndIndex + 1;

            tviTmp.PreviewMouseRightButtonDown += TreeViewItem_PreviewMouseRightButtonDown;
            myTreeView.Items.Add(tviTmp);
        }