1

我正在使用WinrtXamlToolkit中的TreeView。此控件的默认行为是在双击标题时展开嵌套项。负责此操作的代码在此处(TreeViewItem.cs 第 1205 行)

private void OnHeaderMouseLeftButtonDown(object sender, PointerRoutedEventArgs e)
        {
            if (Interaction.AllowMouseLeftButtonDown(e))
            {
                // If the event hasn't already been handled and this item is
                // focusable, then focus (and possibly expand if it was double
                // clicked)
                if (!e.Handled && IsEnabled)
                {
                    if (Focus(FocusState.Programmatic))
                    {
                        e.Handled = true;
                    }

                    // Expand the item when double clicked
                    if (Interaction.ClickCount % 2 == 0)
                    {
                        bool opened = !IsExpanded;
                        UserInitiatedExpansion |= opened;
                        IsExpanded = opened;

                        e.Handled = true;
                    }
                }

                Interaction.OnMouseLeftButtonDownBase();
                OnPointerPressed(e);
            }
        }

有没有办法改变这种行为以在单击或点击时展开项目而不实际将控件及其所有相关类复制到我的项目中?

仅仅为了更改几行代码就这样做似乎有点过头了。

4

1 回答 1

1

我试图用那个 TreeView 做拖放的东西,并且处于类似的情况。我的第一步是实际复制所有 TreeView 及其相关类,而且还有很多。发生了很多内部事情,在一堆其他事情停止工作后,我几乎放弃了干涉它。

所以我的解决方案是在里面有一个特定的控件ItemTemplate来为我处理拖动。对你来说,这将是你处理Button的。Click在事件处理程序中,您将向上导航到您的可视化树TreeViewItem并更改IsExpanded.

于 2016-07-07T11:37:21.327 回答