列表框中的自我工具提示
self tooltip in listbox
我有一个绑定到某些 ObservableCollection<string>
的列表框,我希望每一行的工具提示都是行内容。
我试过:
<ListBox ItemsSource="{Binding MyList}">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="ToolTip" Value="{Binding MyList}"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
在视图模型中:
public ObservableCollection<string> _myList;
public ObservableCollection<string> MyList
{
get { return _myList; }
set
{
if (value != this._myList)
_myList = value;
RaisePropertyChanged("MyList");
}
}
但它不显示工具提示
ListBoxItem 的 DataContext 是 MyList 中的一个元素。
<ListBox ItemsSource="{Binding MyList}">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="ToolTip" Value="{Binding}"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
我有一个绑定到某些 ObservableCollection<string>
的列表框,我希望每一行的工具提示都是行内容。
我试过:
<ListBox ItemsSource="{Binding MyList}">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="ToolTip" Value="{Binding MyList}"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
在视图模型中:
public ObservableCollection<string> _myList;
public ObservableCollection<string> MyList
{
get { return _myList; }
set
{
if (value != this._myList)
_myList = value;
RaisePropertyChanged("MyList");
}
}
但它不显示工具提示
ListBoxItem 的 DataContext 是 MyList 中的一个元素。
<ListBox ItemsSource="{Binding MyList}">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="ToolTip" Value="{Binding}"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>