我是WPF的新手。我在下面的应用程序中使用了listview是XAML: -
<ListView x:Name="lstviewMeters" Grid.Row="2" ItemContainerStyle="{StaticResource MeterRowStyle}" Height="260" Margin="0,73,31,0" VerticalAlignment="Top" Width="597" AlternationCount="2" ItemsSource="{Binding}" HorizontalAlignment="Right">
<ListView.View>
<GridView >
<GridViewColumn Header="Feeder" Width="125" DisplayMemberBinding="{Binding MeterName}" >
<GridViewColumn.HeaderTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Feeder" Padding="9,4,3,3"/>
</StackPanel>
</DataTemplate>
</GridViewColumn.HeaderTemplate>
</GridViewColumn>
<GridViewColumn Header="ID" Width="120" DisplayMemberBinding="{Binding MeterID}">
<GridViewColumn.HeaderTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="ID" Padding="9,4,3,3"/>
</StackPanel>
</DataTemplate>
</GridViewColumn.HeaderTemplate>
</GridViewColumn>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
现在我想在ListviewGridview的每个单元格上显示工具提示。什么是在单元格上显示自定义样式工具提示的最佳方法。我用谷歌搜索但没有得到适当的解决方案 是否有相同的解决方案
答案 0 :(得分:1)
创建CellTemplate然后将工具提示添加到TextBlock
<ListView x:Name="lstviewMeters" Grid.Row="2" ItemContainerStyle="{StaticResource MeterRowStyle}" Height="260" Margin="0,73,31,0" VerticalAlignment="Top" Width="597" AlternationCount="2" ItemsSource="{Binding}" HorizontalAlignment="Right">
<ListView.View>
<GridView >
<GridViewColumn Header="Feeder" Width="125">
<GridViewColumn.CellTemplate>
<DataTemplate >
<TextBlock Text="{Binding MeterName}" ToolTip="{Binding MeterName}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
<GridViewColumn.HeaderTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Feeder" Padding="9,4,3,3"/>
</StackPanel>
</DataTemplate>
</GridViewColumn.HeaderTemplate>
</GridViewColumn>
<GridViewColumn Header="ID" Width="120">
<GridViewColumn.CellTemplate>
<DataTemplate >
<TextBlock Text="{Binding MeterID}" ToolTip="{Binding MeterID}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
<GridViewColumn.HeaderTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="ID" Padding="9,4,3,3"/>
</StackPanel>
</DataTemplate>
</GridViewColumn.HeaderTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>