Popup for Listview RRS feed

  • Question

  • Goal:
    When you have the cursor in one of of the listview's row, a pop up, with text information, should display.

    If you select a new row in the listview a new text information should display.

    How should I do it? I cannot find a tutorial for it?

    - The size of the popup is the same.
    - I'm using C# with WPF.

    Friday, June 20, 2014 8:53 PM


  • You could define a Popup element and display and hide this by handling the SelectionChanged event of the ListView and/or the MouseEnter and MouseLeave events of the ListViewItems:

            <ListView x:Name="lv" SelectionChanged="lv_SelectionChanged">
                    <Style TargetType="ListViewItem">
                        <EventSetter Event="MouseEnter" Handler="OnMouseEnter"/>
                        <EventSetter Event="MouseLeave" Handler="OnMouseLeave"/>
                        <GridViewColumn DisplayMemberBinding="{Binding}" Header="..."/>
            <Popup x:Name="popup">
                <Grid Background="Silver" Width="100" Height="100">
                    <TextBlock Text="{Binding}"/>

    private void lv_SelectionChanged(object sender, SelectionChangedEventArgs e)
                ListViewItem lvi = lv.ItemContainerGenerator.ContainerFromItem(lv.SelectedItem) as ListViewItem;
            private void OnMouseEnter(object sender, MouseEventArgs e)
                ListViewItem lvi = sender as ListViewItem;
            private void OnMouseLeave(object sender, MouseEventArgs e)
                popup.IsOpen = false;
            private void ShowPopup(ListViewItem lvi)
                popup.IsOpen = false;
                popup.PlacementTarget = lvi;
                popup.Placement = PlacementMode.Center;
                popup.DataContext = lvi.DataContext;
                popup.IsOpen = true;

    Sunday, June 22, 2014 7:49 PM