我正在使用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);
}
}
有没有办法改变这种行为以在单击或点击时展开项目而不实际将控件及其所有相关类复制到我的项目中?
仅仅为了更改几行代码就这样做似乎有点过头了。