WinrtXamlToolkit TreeView使用单击而不是双击进行扩展

时间:2016-07-07 11:23:58

标签: c# xaml uwp winrt-xaml-toolkit

我正在使用TreeView中的WinrtXamlToolkit。此控件的默认行为是双击标题时展开嵌套项。负责此操作的代码在(TreeViewItem.cs line 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);
            }
        }

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

这样做只是为了改变几行代码似乎有点过头了。

1 个答案:

答案 0 :(得分:1)

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

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

相关问题