0

샘플에서 보았 듯이 사용자의 연락처 목록을 LongListSelector에 바인딩합니다.사용자 연락처 찾기 : 데이터 바인딩 및 LongListSelector (WP8)를 사용할 때 검색과 일치하는 이름의 일부를 강조 표시합니다.

<phone:PhoneApplicationPage.Resources> 
... 
    <DataTemplate x:Key="AddrBookItemTemplate" > 
     <ListBoxItem> 
      <StackPanel>      
       <TextBlock Text="{Binding Path=DisplayName, Mode=OneWay}" FontFamily="Segoe WP" FontSize="25" /> 
       <TextBlock Text="{Binding Path=PhoneNumbers[0].PhoneNumber, Mode=OneWay}" FontFamily="Segoe WP Light" FontSize="20" /> 
      </StackPanel> 
     </ListBoxItem> 
    </DataTemplate> 
... 
</phone:PhoneApplicationPage.Resources> 

...

<Grid x:Name="ContentPanel"> 
    <phone:LongListSelector 
     x:Name="AddrBook" 
     JumpListStyle="{StaticResource AddrBookJumpListStyle}" 
     GroupHeaderTemplate="{StaticResource AddrBookGroupHeaderTemplate}" 
     ItemTemplate="{StaticResource AddrBookItemTemplate}" 
     LayoutMode="List" 
     IsGroupingEnabled="true" 
     HideEmptyGroups ="true" 
     SelectionChanged="AddrBook_SelectionChanged"/> 
</Grid> 

그리고 특정 이름 (LINQ를 사용하는)이 방법은 사용자의 검색을하고 있어요 :

contactsList = contactsEnum.Where(m => m.PhoneNumbers.Count() > 0 && (m.DisplayName.Split(' ').ToList().Any(p => p.ToLower().StartsWith(tbxSearch.Text.ToLower())) || (m.PhoneNumbers.Any(y => y.PhoneNumber.StartsWith(tbxSearch.Text))))).ToList(); 
AddrBook.ItemsSource = contactsList; // With IsGroupingEnabled=false 
,369을

검색과 일치하는 이름의 일부를 강조 표시하는 방법을 찾고 있는데 데이터 바인딩을 만드는 방식으로이 작업을 수행 할 수 없습니다. ...

하이라이트를 할 수 있을까요?

답변

0

당신이 뭔가를 할 수있는 단어는 sub strings 또는 Collection, 당신은 할 수 단순히 highlight을 내 될 수있는 단어로 textbox 경기 내에서 입력 할 때마다!

string[] substrings = regex.Split(Content.Text); 
Content.Inlines.Clear(); 

foreach (var item in substrings) 
{ 
    //if a word from the content matches the search-term 
    if (regex.Match(item).Success) 
    { 
     //create a 'Run' and add it to the TextBlock 
     Run run = new Run(item); 
     run.Foreground = Brushes.Red; 
     Content.Inlines.Add(run); 
    } 
    else //if no match, just add the text again 
     Content.Inlines.Add(item); 
} 

참고 : Is there a way I can highlight specific text in a textbox?

How to Highlight the result from context sensitive search in windows phone 7?