动态生成的列标题上的WPF Click事件

时间:2016-03-01 13:05:50

标签: c# .net wpf gridview mvvm

我有一个包含GridView的ListView。它的列是动态生成的,具有类的附加属性" GridViewColumns"像这样:

<GridView 
                ColumnHeaderTemplate="{StaticResource HeaderFilter}"
                self:GridViewColumns.DisplayMemberMember="DisplayMember"
                self:GridViewColumns.DisplayMemberFormatMember="DisplayMemberFormat"
                self:GridViewColumns.WidthMember="Width"
                self:GridViewColumns.HeaderTextMember="HeaderText"
                self:GridViewColumns.ImageTemplateMember="{StaticResource ImageTemplate}"
                self:GridViewColumns.ColumnsSource="{Binding WorkItemsColumns}"/>

GridViewColumns.cs中的定义示例:

[AttachedPropertyBrowsableForType(typeof(GridView))]
    public static string GetHeaderTextMember(DependencyObject obj)
    {
        return (string)obj.GetValue(HeaderTextMemberProperty);
    }

    public static void SetHeaderTextMember(DependencyObject obj, string value)
    {
        obj.SetValue(HeaderTextMemberProperty, value);
    }


    public static readonly DependencyProperty HeaderTextMemberProperty =
        DependencyProperty.RegisterAttached("HeaderTextMember", typeof(string), typeof(GridViewColumns), new UIPropertyMetadata(null));

gridview标题的模板:

            <DataTemplate x:Key="HeaderFilter" DataType="GridViewColumnHeader">
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
                    <Button Name="FilterButton" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Height="18" Margin="5,0,5,0">
                        <Image Source="Wfl.Presentation.Tibco;component/Resources/Images/filter2.png" />
                    </Button>
                    <TextBlock x:Name="Entete" Text="{Binding}"  FontSize="14"/>
                </StackPanel>
            </DataTemplate>

如何在GridView的标题上定义Click事件?

0 个答案:

没有答案