using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace WPF01.pages { /// /// Логика взаимодействия для Product.xaml /// public partial class Product : Page { db2.Test02Entities database; public Product() { InitializeComponent(); database = new db2.Test02Entities(); LoadProduct(""); } void LoadProduct(string search) { List products; if (search.Length == 0) { products = database.Product.ToList(); } else { products = database.Product.Where(p => p.Title.IndexOf(search) > -1).ToList(); } int productCouter = 0; ProductGrid.Children.Clear(); for (int i = 0; i < 2; i++) { for (int j = 0; j < 3; j++) { // 5 < 4 if ((products.Count - 1) < productCouter) { return; } Border border = new Border(); border.BorderBrush = Brushes.Gray; border.BorderThickness = new Thickness(1); border.Margin = new Thickness(10); border.Background = Brushes.White; ProductGrid.Children.Add(border); Grid.SetRow(border, i); Grid.SetColumn(border, j); StackPanel stackPanel = new StackPanel(); border.Child = stackPanel; //< Image Source = "/WPF01;component/Товары автосервиса/E9308929.jpg" Height = "129" Margin = "20,10,20,0" /> Image image = new Image(); BitmapImage bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.UriSource = new Uri("pack://application:,,,/" + products[productCouter].MainImagePath); bitmapImage.EndInit(); image.Source = bitmapImage; image.Height = 130; stackPanel.Children.Add(image); Label l1 = new Label(); l1.Content = products[productCouter].Title; l1.FontSize = 10; l1.Foreground = Brushes.DarkMagenta; l1.Padding = new Thickness(0); l1.Margin = new Thickness(0); l1.HorizontalContentAlignment = HorizontalAlignment.Center; stackPanel.Children.Add(l1); Label l2 = new Label(); l2.Content = products[productCouter].Cost; stackPanel.Children.Add(l2); if (products[productCouter].IsActive == false) { Label l3 = new Label(); l3.Content = "неактивен"; stackPanel.Children.Add(l3); border.Background = Brushes.LightGray; } productCouter++; } } } private void TextBox_KeyUp(object sender, KeyEventArgs e) { LoadProduct(Search.Text); } } }