查看声明:
<ListBox x:Name="LboxItems" ItemsSource="{Binding Items}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Name="itemTemplate" Text="{Binding Info}" Foreground="{Binding Foreground}"></TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
代码背后:
for (int i = 0; i < LboxItems.Items.Count; i++)
{
var item= LboxItems.Items[i] as TestItem;
if (monitorItem != null)
{
var index = item.Info.IndexOf(textToFind);
//TODO textToFind has been found therefore highlight it
}
}
是否可以在WPF中高亮显示ListBox中的文本片段?