<Window x:Class="wpf2.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="600" Width="300"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"></RowDefinition> <RowDefinition Height="*"></RowDefinition> </Grid.RowDefinitions> <StackPanel Orientation="Horizontal" Grid.Row="0"> <TextBox x:Name="txtCustomerFilter" CharacterCasing="Upper" Width="100" Margin="5" KeyUp="ButtonSearch_Click"></TextBox> <Button x:Name="ButtonSearch" Width="50" Margin="5" Click="ButtonSearch_Click">Search</Button> </StackPanel> <ListView Name="lv2" HorizontalContentAlignment="Stretch" ScrollViewer.VerticalScrollBarVisibility="Visible" Grid.Row="1" Background="DarkBlue"> <ListView.ItemTemplate> <DataTemplate> <Border Margin="5" BorderThickness="1" BorderBrush="SlateGray" CornerRadius="4" Background="CadetBlue"> <Grid Margin="3"> <Grid.RowDefinitions> <RowDefinition></RowDefinition> <RowDefinition></RowDefinition> <RowDefinition></RowDefinition> <RowDefinition></RowDefinition> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition></ColumnDefinition> </Grid.ColumnDefinitions> <StackPanel Orientation="Horizontal"> <TextBlock FontWeight="Bold" Text="{Binding Path=custno}"></TextBlock> <TextBlock Text="{Binding Path=company}" Margin="5,0,0,0"></TextBlock> </StackPanel> <StackPanel Grid.Row="1" Orientation="Horizontal"> <TextBlock>Phone:</TextBlock> <TextBlock Text="{Binding Path=phone}" Margin="5,0,0,0"></TextBlock> </StackPanel> <StackPanel Grid.Row="2" Orientation="Horizontal"> <TextBlock>Fax:</TextBlock> <TextBlock Text="{Binding Path=faxno}" Margin="5,0,0,0"></TextBlock> </StackPanel> </Grid> </Border> </DataTemplate> </ListView.ItemTemplate> </ListView> </Grid> </Window>
public void ButtonSearch_Click(object sender, RoutedEventArgs e) { DataClasses1DataContext db = new DataClasses1DataContext(); var CustomerFilter='%'+txtCustomerFilter.Text+'%'; var customers = from a in db.customers where SqlMethods.Like(a.custno,CustomerFilter) || SqlMethods.Like(a.company,CustomerFilter) orderby a.custno select new { a.custno, a.company, a.phone, a.faxno }; lv2.ItemsSource = customers; }