ListViewItem 工具提示 WPF

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28471309/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 12:56:35  来源:igfitidea点击:

ListViewItem tooltip WPF

c#wpfxamllistviewitem

提问by avechuche

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

我需要的是,当每个 listviewitem 的鼠标在工具提示中显示每个列表的所有数据时。

This is a part of my viewmdel

这是我的 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

我的.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.

感谢您的帮助。我尝试了几件事,但没有好的结果。

回答by dymanoid

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

您可以定义一个ItemContainerStyle来设置您的工具提示模板和内容。

See an example below, here I define an UniformGridto 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.

请参见下面的示例,这里我定义了一个UniformGrid以在一列中显示多个文本行。您可以随意设置工具提示。您仍然需要告诉视图需要在工具提示中显示哪些数据属性。

<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>