我在WPF中有一个列表框,如下所示
<ListBox Name="lstName" DisplayMemberPath ="ListName" ToolTip="{Binding Path=ListName}" />
我的要求是,无论我在列表框中显示什么项,都应该出现在工具提示中。也就是说,如果这些项是“项目1”、“项目2”等,则当用户通过鼠标指向“项目1”时,工具提示应该显示“项目1”。其他项也是如此。
因此,我的DisplayMemberPath设置为我应该显示的属性(它已经正确显示)。然而,工具提示根本没有出现。
实体如下:
public class ItemList
{
public string ListName { get; set; }
}
绑定操作的步骤如下:
this.lstName.ItemsSource = GetData(); // Assume that the data is coming properly