ListBoxItem的工具提示绑定到字符串列表时

Irf*_*fan 1 wpf listbox tooltip mvvm

当ListBox控件绑定到字符串列表时,我们如何显示ListBoxItem的工具提示.下面是我的ListBox的源代码,其中ConcernedConditions是List类型.

<ListBox ItemsSource="{Binding ConcernedConditions}" Style="{StaticResource CustomStyle}">
    <ListBox.ItemContainerStyle>
        <Style TargetType="{x:Type ListBoxItem}">
            <Setter Property="Template"> 
                <Setter.Value> 
                    <ControlTemplate TargetType="{x:Type ListBoxItem}"> 
                        <ContentPresenter /> 
                    </ControlTemplate> 
                </Setter.Value> 
            </Setter>
        </Style>
    </ListBox.ItemContainerStyle>
</ListBox>
Run Code Online (Sandbox Code Playgroud)

And*_*ndy 5

你可以设置列表框的项目模板的样式并在其中放置一个文本块,然后使用它的工具提示属性吗?

<ListBox ItemsSource="{Binding Strings}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding}" ToolTip="Here is a tooltip"/>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)