Live Chat Icon For mobile
Live Chat Icon

How do I show tooltips for the listview items?

Platform: WPF| Category: ListView

You can do so by first defining a DataTemplate for the corresponding columns as follows. Sample code can be seen with better formatting in this thread (ListView Column ToolTip)

[XAML]
<Page xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
      xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
    <StackPanel>
        <StackPanel.Resources>
            <DataTemplate x:Key='nameTemplate'>
                <TextBlock Text='{Binding Name}'  Margin='-6,0'>
                    <TextBlock.ToolTip>
                        <ToolTip>
                            <TextBlock Foreground='Green' Text='{Binding Name}'/>
                        </ToolTip>
                    </TextBlock.ToolTip>
                </TextBlock>
            </DataTemplate>
            <DataTemplate x:Key='namespaceTemplate'>
                <TextBlock Text='{Binding Namespace}'  Margin='-6,0'>
                    <TextBlock.ToolTip>
                        <ToolTip>
                            <TextBlock Foreground='Green' Text='{Binding Namespace}'/>
                        </ToolTip>
                    </TextBlock.ToolTip>
                </TextBlock>
            </DataTemplate>
        </StackPanel.Resources>
        <ListView>
            <ListView.ItemContainerStyle>
                <Style TargetType='ListViewItem'>
                    <Setter Property='HorizontalContentAlignment' Value='Stretch'/>
                    <Setter Property='VerticalContentAlignment' Value='Stretch'/>
                </Style>
            </ListView.ItemContainerStyle>
            <ListView.View>
                <GridView>
                    <GridViewColumn CellTemplate='{StaticResource nameTemplate}' Width='300' Header='Name'/>
                    <GridViewColumn CellTemplate='{StaticResource namespaceTemplate}' Width='300' Header='Namespace'/>
                </GridView>
            </ListView.View>
            <x:Type TypeName='Visual'/>
            <x:Type TypeName='FrameworkElement'/>
            <x:Type TypeName='FrameworkContentElement'/>
        </ListView>
    </StackPanel>
</Page>

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.