Windows Phone 7のテキストボックスに入力されたテキストに従って、検索結果を強調表示する必要があります。
通常のwpfコードはWindowsPhone7では機能しません。誰かがWindowsPhone7でこれを達成する方法を言います
実際、これは連絡先リストに入力するために使用しているxamlリストボックスです。
<ListBox Name="ContactList" ItemsSource="{Binding}" Margin="14,85,14,28" Foreground="White" SizeChanged="ContactList_SizeChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Border BorderThickness="2" HorizontalAlignment="Left" VerticalAlignment="Center" BorderBrush="{StaticResource PhoneAccentBrush}" >
<Image Source="{Binding Converter={StaticResource ContactPictureConverter}}" Width="48" Height="48" Stretch="Fill" Name="img1" />
</Border>
<TextBlock Name="ContactResults" Text="{Binding Path=DisplayName, Mode=OneWay}" FontSize="{StaticResource PhoneFontSizeExtraLarge}" Margin="18,8,0,0" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBox Name="contactFilterString" Margin="0,0,0,528" TextChanged="contactFilterString_TextChanged" />
C#コード、
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
//using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.UserData;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.ObjectModel;
using Microsoft.Phone.Shell;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using System.Text.RegularExpressions;
namespace SmartContactsApp
{
public partial class MainPage : PhoneApplicationPage
{
private List<Address> lstAddress = new List<Address>();
public string addressJson = string.Empty;
// Constructor
public MainPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
CreateSecondaryTile();
}
/// <summary>
/// To List all the Contacts. . .
/// </summary>
private void ContactListing()
{
ContactList.DataContext = null;
Contacts cons = new Contacts();
cons.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(Contacts_SearchCompleted);
cons.SearchAsync(contactFilterString.Text, FilterKind.DisplayName, "Contacts");
}
/// <summary>
/// To Fetch All Contacts from Mobile Contacts. . .
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void Contacts_SearchCompleted(object sender, ContactsSearchEventArgs e)
{
try
{
ContactList.DataContext = e.Results;
}
catch (Exception)
{
throw;
}
}
private void contactFilterString_TextChanged(object sender, TextChangedEventArgs e)
{
ContactListing();
}
}
これでハイライトする方法、
前もって感謝します!