gpt4 book ai didi

wpf - 如何为每个 ListBoxItem 设置工具提示

转载 作者:行者123 更新时间:2023-12-02 15:38:43 25 4
gpt4 key购买 nike

我有一个 ListBox 控件;我如何使用下面的代码为每个 ListBoxItem 设置 ToolTip

<ListBox Name="FillSelections" 
VerticalContentAlignment="Stretch"
Margin="1, 3, 1, 3"
IsEnabled="True"
Grid.Column="0"
Background="Transparent"
HorizontalContentAlignment="Center"
SelectedItem="{Binding SelectedColor}"
SelectionMode="Single"
Style="{StaticResource HorizontalListBoxStyle}"
ItemsSource="{Binding FillColors}"
ItemTemplate="{StaticResource ColorsItemTemplate}">
</ListBox>

<DataTemplate x:Key="ColorsItemTemplate">
<Border Width="20"
Height="16"
BorderBrush="Black"
BorderThickness="1">
<Border.Background>
<SolidColorBrush Color="{Binding}" />
</Border.Background>
<Path Stroke="Red"
StrokeThickness="3"
x:Name="abc"
Visibility="Hidden">
<Path.Data>
<LineGeometry StartPoint="0,16" EndPoint="20,0"/>
</Path.Data>
</Path>
</Border>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding}" Value="#00FFFFFF">
<Setter TargetName="abc" Property="Visibility" Value="Visible"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>

最佳答案

尝试这样的事情

<ListBox Width="400" Margin="10" 
ItemsSource="{Binding Source={StaticResource myTodoList}}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=TaskName}"
ToolTipService.ToolTip="{Binding Path=TheTooltipText}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

当然,请根据您的绑定(bind)源调整 ItemsSource 绑定(bind),并根据您实际想要显示的列表中对象的任何公共(public)属性调整绑定(bind)路径部分。

关于wpf - 如何为每个 ListBoxItem 设置工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12430835/

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