Select text in list from linq query
Windows 10 Universal App
Hi, I like to highlight text in ListView
from linq. I ListView
, ListviewItemtemplate
, DataTemplate
, Textbox
.
Textbox
is required.
<ListView x:Name="listView" Background="#FFCCD0D6" Margin="0,240,0,60" IsItemClickEnabled="True" HorizontalAlignment="Right" Width="1095" ScrollViewer.HorizontalScrollBarVisibility="Auto" Tapped="listView_Tapped" DoubleTapped="listView_DoubleTapped" SelectionChanged="listView_SelectionChanged">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Margin="4" Text="{Binding Vorname}" HorizontalAlignment="Left"/>
<TextBlock Margin="4" Text="{Binding Nachname}" HorizontalAlignment="Left"/>
I'm looking with linq with text from a textbox. This works great. I get the items I was looking for. But know how I could highlight the desired text. I cannot find a solution.
thanks for the help
Olli
source to share
You won't get this easily, I got this request from the client and I ended up splitting the TextBlock in five properties <Run>
to cover the whole possible situation, the hard part was handling the results and splitting the lines accordingly:
<TextBlock TextWrapping="Wrap">
<Bold><Run Text="{Binding Text1}" /></Bold>
<Run Text="{Binding Text2}" />
<Bold><Run Text="{Binding Text3}" /></Bold>
<Run Text="{Binding Text4}" />
<Bold><Run Text="{Binding Text5}" /></Bold>
</TextBlock>
EDIT:
There is also a library claiming to do this task, I've never played around with it, but you can try:
HtmlTextBlock for WPF
source to share