我的要求: - 逐字母搜索txtsearch并显示ITMNAME匹配的字母(列表框中的文本块)并突出显示该特定字符串..
我的xaml ......
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="DataTemplate1" >
<Border BorderBrush="LightGray" BorderThickness="1" Height="150" Width="500" >
<Grid Width="500" Height="150" Background="White" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.9*"/>
<ColumnDefinition Width="2.5*"/>
<ColumnDefinition Width="1.5*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Image Name="imgitem" Grid.Column="0" Height="Auto" Width="Auto" Source="{Binding ImgSource}" Margin="0,5,4,4" HorizontalAlignment="Left" />
<TextBlock x:Name="txtbindprice" Text="{Binding _PRICE,ConverterCulture=en-IN,StringFormat=C}" TextWrapping="Wrap" Grid.Column="1" Width="350" Foreground="Black" Height="60" Margin="40,70,20,-10"/>
<TextBlock x:Name="txtFinalTotal" Text="{Binding _FinalTotal}" TextWrapping="Wrap" Grid.Column="1" Width="350" Foreground="Red" Height="60" Margin="40,115,20,-10"/>
<TextBlock x:Name="txtITMNAME" Text="{Binding _ITMNAME }" Padding="1" Tap="ItmName_Tapped" TextDecorations="Underline" FontSize="24" TextWrapping="Wrap" Grid.Column="1" FontWeight="Normal" TextTrimming="WordEllipsis" Foreground="OrangeRed" Width="Auto" Height="150" Margin="30,25,10,-10"/>
<c4f:RoundButton Grid.Column="2" Name="btntick" Click="btntick_Click" Grid.Row="0" FontSize="25" HorizontalAlignment="Right" Background="LightGray" Foreground="DarkGray" Margin="10,20,45,10" />
</Grid>
</Border>
</DataTemplate>
<ListBox Height="Auto" Name="lstbxmanual" SelectionMode="Extended" ItemTemplate="{StaticResource DataTemplate1 }" Width="475" Margin="2,192,0,-39" Background="White" HorizontalAlignment="Left" Grid.RowSpan="2">
</ListBox>
<TextBox x:Name="txtSearch" BorderThickness="1" BorderBrush="CadetBlue" KeyUp="txtSearch_KeyUp" GotFocus="txtsearch_gotFocus" LostFocus="txtsearch_lostFocus" FontSize="24" Background="White" Height="85" TextAlignment="Left" Margin="1,-30,-2,30" />
我的viewmodel
#region "Bind"
public class BindData
{
public BitmapImage ImgSource { get; set; }
public string _ITMNAME { get; set; }
public string _PRICE { get; set; }
public string _FinalTotal { set; get; }
}
#endregion
我的约束力
foreach ()
{
lstbxmanual.Items.Add(new BindData() { ImgSource = base64image(h[2]), _ITMNAME = h[3], _PRICE =string.Concat(ClsCommon.str_CurrencySymbol,h[1]), _FinalTotal = "" });
}
由此我将整个迭代数据绑定到listbox(lstbxmanual)..
textbox event I have included
private void txtSerach_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
// the followig throws an error at li.Equals
//var selectedItems = from li in lstbxmanual.Items
// where li.Equals == txtSearch.Text
// select li.Text;
// the following searches only by index of lstbox
// if (lstbxmanual.Items.Contains(txtSearch.Text))
//{
//}
}
在上面的链接..他们将所有数据绑定到列表然后搜索..我没有使用任何类型的列表..所以我无法实现它..
请帮忙解决这个问题...... 任何查询都会恢复..