Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListViewItem tooltip WPF

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.

like image 592
avechuche Avatar asked Feb 12 '15 07:02

avechuche


1 Answers

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>
like image 69
dymanoid Avatar answered Oct 15 '22 06:10

dymanoid