简体   繁体   English

如何使ListView标头可点击?

[英]How do I make a ListView header to be clickable?

I have a listview containing a header which is supposed to respond when clicked. 我有一个包含标题的listview,应该在单击时响应。

Is there a way to create a clickable ListView header? 有没有一种方法来创建可点击的 ListView标头?

There is no problem in putting for example Button as a header in your ListView : Button例如作为ListView的标题没有问题:

<ListView Width="100" Margin="20">
    <ListView.Header>
        <Button Content="Clickable header" Click="Button_Click"/>
    </ListView.Header>
    <x:String>Sample element</x:String>
    <x:String>Sample element</x:String>
    <x:String>Sample element</x:String>
</ListView>

Of course you can change style of the button to fulfill your needs. 当然,您可以更改按钮的样式来满足您的需求。 Also instead changing the header you can also change HeaderTemplate : 另外,除了更改标题之外,您还可以更改HeaderTemplate

<ListView Width="100" Margin="20" Header="Clickable header">
    <ListView.HeaderTemplate>
        <DataTemplate>
            <Button Content="{Binding}" Click="Button_Click"/>
        </DataTemplate>
    </ListView.HeaderTemplate>
    <x:String>Sample element</x:String>
    <x:String>Sample element</x:String>
    <x:String>Sample element</x:String>
</ListView>

I solved the issue by adding a behavior for ListView.HeaderTemplate: 我通过为ListView.HeaderTemplate添加行为解决了该问题:

<Interactivity:Interaction.Behaviors>
    <Core:EventTriggerBehavior EventName="Tapped" SourceObject="{Binding ElementName=ListViewHeader}">
         <Core:InvokeCommandAction Command="{Binding DataContext.OnShowAllTicketsPressedCommand, ElementName=Project}"/>
    </Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM