1
我正在爲WP8製作一個包含地址列表框的應用程序。地址可以用文本框搜索。 我的問題是,文本框搜索隨機字母后,而不是在開頭的字母。這裏是我的代碼:用文本框搜索第一個字母
VB.net
Private Sub txtSearch_TextChanged(sender As Object, e As TextChangedEventArgs)
If lstRestaurants IsNot Nothing Then
Me.listBox.ItemsSource = lstRestaurants.Where(Function(w) w.Restaurantnaam.ToUpper().Contains(txtSearch.Text.ToUpper()))
End If
End Sub
XAML
<phone:PhoneApplicationPage
x:Class="PhoneApp1.LijstRestaurants"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True">
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel Grid.Row="0" Margin="12,17,0,28"/>
<!--ContentPanel - place additional content here-->
<TextBox x:Name="txtSearch" TextChanged="txtSearch_TextChanged" Text="" Margin="0,-500,0,0" Height="80" ></TextBox>
<ListBox x:Name="listBox" FontSize="26" Height="580" Margin="0,100,0,0">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Restaurantnaam}" Width="440" Margin="10,15,0,0" Height="80"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</phone:PhoneApplicationPage>
有人可以幫我嗎? 謝謝。
這解決了我的問題!謝謝! – Manariba
太好了,不客氣!不要忘記[接受答案](http://stackoverflow.com/help/someone-answers) – har07