-2

我想在 WPF 中创建一个与 windows 应用程序相同的应用程序。当我在 wpf 中使用 treeview 事件时,我没有找到任何类似于 WIndows 应用程序的 treeview_NodeMouseClick 的事件。

//Windows 应用程序代码

    private void tv_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
    {
        if (e.Node != null)
        {
            GetAllchield(e.Node, e.Node.Level);

        }

    }

// GetAllchield

    public void GetAllchield(TreeNode clickednode, int indexDepth)
    {
        if (clickednode.Nodes.Count > 0 && !clickednode.IsExpanded)
        {
            clickednode.Collapse();
            return;
        }
        string[] FullPath = clickednode.FullPath.Split('\\');
        string rootnode = FullPath[0].ToString();
        //get all market for root event type
        int eventTypeID = DictionaryAllActiveEventTypes[rootnode];
        string[] allMarkets = GetAllMarketForEventID(eventTypeID);

        //selecting unque chield node and populating in tree

        for (int i = 0; i < allMarkets.Length; i++)
        {

            if (allMarkets[i].Contains(clickednode.Text))
            {

                string[] marketDetails = allMarkets[i].Split('~');
                int marketID = Convert.ToInt32(marketDetails[0]);
                string MarketName = marketDetails[1].ToString();
                string MarketStatus = marketDetails[3].ToString();
                string EventHeirarchy = marketDetails[6].ToString();


                string Menupath = marketDetails[5].ToString();
                string[] Arrmenupath = Menupath.Trim(':').Split('\\');

                string chieldText = "";



                if (indexDepth == 0)
                {
                    if (rootnode == "Cricket" || rootnode == "Tennis" || rootnode == "Golf" || rootnode == "Rugby")
                    {
                        if (Arrmenupath[2].Contains("Group") && Arrmenupath[2].Length == 7)
                        {
                            if ((indexDepth + 3) <= Arrmenupath.Length - 1)
                            {
                                chieldText = Arrmenupath[indexDepth + 3].ToString();
                            }
                        }
                        else
                        {
                            if ((indexDepth + 2) <= Arrmenupath.Length - 1)
                                chieldText = Arrmenupath[indexDepth + 2].ToString();
                        }
                    }
                    else
                        if ((indexDepth + 2) <= Arrmenupath.Length - 1)
                            chieldText = Arrmenupath[indexDepth + 2].ToString();
                }
                else
                {
                    if (Arrmenupath[Arrmenupath.Length - 1] == clickednode.Text)
                        chieldText = MarketName;
                    else
                    {

                        if (allMarkets[i].Contains(clickednode.Text) && allMarkets[i].Contains(clickednode.Parent.Text) && allMarkets[i].Contains(rootnode))
                        {
                            if (rootnode == "Cricket" || rootnode == "Tennis" || rootnode == "Golf" || rootnode == "Rugby")
                            {
                                if (Arrmenupath[2].Contains("Group") && Arrmenupath[2].Length == 7)
                                {
                                    if ((indexDepth + 3) <= Arrmenupath.Length - 1)
                                    {
                                        chieldText = Arrmenupath[indexDepth + 3].ToString();
                                    }
                                }
                                else
                                {
                                    if ((indexDepth + 2) <= Arrmenupath.Length - 1)
                                        chieldText = Arrmenupath[indexDepth + 2].ToString();
                                }
                            }
                            else
                                if ((indexDepth + 2) <= Arrmenupath.Length - 1)
                                    chieldText = Arrmenupath[indexDepth + 2].ToString();
                        }
                    }
                }


                //check whether node is already added

                //if (chieldText.Contains("MiWay"))
                //{ }


                if (!string.IsNullOrEmpty(chieldText))
                {
                    if (clickednode.Nodes.Count >= 1)
                    {
                        bool doesNodeAlreadyExist = false;
                        foreach (TreeNode node in clickednode.Nodes)
                        {
                            if (node.Text == chieldText)
                            {
                                doesNodeAlreadyExist = true;
                                break;
                            }
                        }
                        if (!doesNodeAlreadyExist)
                        {
                            clickednode.Nodes.Add(chieldText);
                        }
                    }
                    else
                    {
                        clickednode.Nodes.Add(chieldText);
                    }
                }


            }
        }
        clickednode.Expand();
    }

我想在 WPF 中使用相同的。请帮助我,或者如果你明白了。

4

1 回答 1

0

您可以使用 MouseLeftButtonDown 并检查 sender 参数或使用 SelectedItemChanged

于 2012-05-17T11:33:23.220 回答