gpt4 book ai didi

wpf - 绑定(bind)到字符串列表时的列表框项目的工具提示

转载 作者:行者123 更新时间:2023-12-03 10:20:57 24 4
gpt4 key购买 nike

当 ListBox 控件绑定(bind)到字符串列表时,我们如何显示 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>

最佳答案

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

<ListBox ItemsSource="{Binding Strings}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" ToolTip="Here is a tooltip"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

关于wpf - 绑定(bind)到字符串列表时的列表框项目的工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13254395/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com