prevent WPF的ListView头双击自动调整大小列 [英] prevent wpf listview header double click autosizes column

查看:140
本文介绍了prevent WPF的ListView头双击自动调整大小列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在那里我有模板列标题和列表视图项目也模板列表视图。不过我有一些在网格视图中的行不同tempalates。当在列表视图的列标题,您可以拖动列的宽度,用户双击,列标题会自动调整,这意味着它会增加它的大小。这会导致一个问题,我是因为我的列标题的宽度是同步不再与列在我行模板的宽度。

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 view. When a user double clicks on the list view column header where you can drag the width of the column, the column header will auto resize, meaning it will increase its size. This causes a problem for me because my column header width is no longer in sync with the width of the columns in my row templates.

是否有一个快速简便的方法来prevent在列的标题此双击行为?

Is there a quick and easy way to prevent this double click behavior on the header of a column?

推荐答案

是,设置在的ListView 本身就是一个双击处理程序。然后在处理程序中,使用code是这样的:

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<GridViewColumnHeader>(e.OriginalSource as DependencyObject) != null)
        e.Handled = true;
}

其中, TryFindParent 的定义是:

public static T TryFindParent<T>(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<T>(parent);
}

这篇关于prevent WPF的ListView头双击自动调整大小列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆