隐藏listviewitem的工具提示

时间:2013-08-02 22:57:30

标签: wpf listview tooltip

我正在使用WPF listview。我的要求是在listview项目上显示工具提示。以下XAML适用于我。

<ListView Height="174" HorizontalAlignment="Left" ItemsSource="{Binding SystemsList}" Margin="12,27,0,0" Name="listView1" VerticalAlignment="Top" Width="456">
        <ListView.View>
            <GridView>
                <GridViewColumn Header="System Name" Width="Auto"  DisplayMemberBinding="{Binding SystemName}"/>
                <GridViewColumn Header="Network Name" Width="Auto" DisplayMemberBinding="{Binding SystemComputerName}"/>
                <GridViewColumn Header="IP Address" Width="Auto" DisplayMemberBinding="{Binding SystemIPAddress}"/>
            </GridView>
        </ListView.View>
        <ListView.ItemContainerStyle>
            <Style TargetType="{x:Type ListViewItem}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=MaxConnectionsLimitReached}" Value ="true" >
                        <Setter Property="IsEnabled" Value="False"/>
                    </DataTrigger>
                </Style.Triggers>
                <Setter Property="ToolTip" Value="{Binding Path=ToolTip1}" />

            </Style>              
        </ListView.ItemContainerStyle>
    </ListView>

但我如何完成以下

1)未显示已禁用行的工具提示。如何展示?

2)我想隐藏某些行的工具提示。

1 个答案:

答案 0 :(得分:1)

 <Style TargetType="{x:Type ListViewItem}">
                <Style.Triggers>
                         <!-- Your DataTrigger -->

                         <!-- For hiding the ToolTip according to SomeProperty -->
                         <DataTrigger Binding="{Binding SomeProperty}" Value="SomeValue">
                              <Setter Property="ToolTip" Value="{x:Null}"/>
                         </DataTrigger>

                </Style.Triggers>
                <Setter Property="ToolTip" Value="{Binding Path=ToolTip1}" />
                <Setter Property=ToolTipService.ShowOnDisabled" Value="True"/> <!-- For Showing ToolTip even on disabled rows -->
            </Style>