ListViewItem tooltip WPF
Asked Answered
A

1

7

What I need is that when mouse per listviewitem show me all data from each in a tooltip.

This is a part of my viewmdel

...
...
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.CommandWpf;
...
...

private ObservableCollection<Articulo> _articulos;

private Articulo _articuloSeleccionado;

        public ObservableCollection<Articulo> Articulos
        {
            get { return _articulos; }
            set
            {
                _articulos = value; 
                RaisePropertyChanged();
            }
        }

        public Articulo ArticuloSeleccionado
        {
            get { return _articuloSeleccionado; }
            set
            {
                _articuloSeleccionado = value;
                RaisePropertyChanged();
            }
        }

My .xalm

            <ListView Name="lvResultado"
                      ItemsSource="{Binding Articulos}"
                      SelectedItem="{Binding ArticuloSeleccionado}">
                <ListView.ItemContainerStyle>
                    <Style TargetType="ListViewItem">
                        <Setter Property="HorizontalContentAlignment" Value="Center"/>
                    </Style>
                </ListView.ItemContainerStyle>
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Código de barras" Width="200" DisplayMemberBinding="{Binding CodigoDeBarras}"/>
                        <GridViewColumn Header="Descripción" Width="250" DisplayMemberBinding="{Binding Descripcion}"/>
                    </GridView>
                </ListView.View>
            </ListView>

Thank you for your help. I tried several things but no good result.

Azpurua answered 12/2, 2015 at 7:5 Comment(2)
You have multiple columns in the grid view. Do you want to see a tooltip for the whole row, or for each cell separately?Rakia
Hello! The listview only shows two properties of the article class. I would like to add a tooltip to show me all the properties of the entire row.Azpurua
R
18

You can define an ItemContainerStyle that would set your tooltip template and content.

See an example below, here I define an UniformGrid to display multiple text lines in one column. You are free to setup your tooltip as you wish. You still need to tell the view which data properties need to be displayed in the tooltip.

<ListView ItemsSource="{Binding Articulos}">
  <ListView.ItemContainerStyle>
    <Style TargetType="{x:Type ListViewItem}">
      <Setter Property="ToolTip">
        <Setter.Value>
          <UniformGrid Columns="1">
            <TextBlock Text="{Binding CodigoDeBarras}"/>
            <TextBlock Text="{Binding Descripcion}"/>
            <TextBlock Text="{Binding AnyOtherProperty}"/>
          </UniformGrid>
        </Setter.Value>
      </Setter>
    </Style>
  </ListView.ItemContainerStyle>
</ListView>
Rakia answered 12/2, 2015 at 9:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.