prevent wpf listview header double click autosizes column

后端 未结 2 1399
北恋
北恋 2020-12-21 20:06

I have a listview where I have templated the column headers and the listview items are templated also. However I have different tempalates for some of the rows in the grid

2条回答
  •  无人及你
    2020-12-21 20:47

    Yes, set up a double-click handler on the ListView itself. Then in the handler, use code like this:

    private void ListView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
    {
        if (TryFindParent(e.OriginalSource as DependencyObject) != null)
            e.Handled = true;
    }
    

    Where TryFindParent is defined as:

    public static T TryFindParent(DependencyObject current) where T : class
    {
        DependencyObject parent = VisualTreeHelper.GetParent(current);
    
        if (parent == null) return null;
    
        if (parent is T) return parent as T;
        else return TryFindParent(parent);
    }
    

提交回复
热议问题