Product.xaml.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace WPF01.pages
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для Product.xaml
  19. /// </summary>
  20. public partial class Product : Page
  21. {
  22. db2.Test02Entities database;
  23. public Product()
  24. {
  25. InitializeComponent();
  26. database = new db2.Test02Entities();
  27. LoadProduct();
  28. }
  29. void LoadProduct()
  30. {
  31. var products = database.Product.ToList();
  32. int productCouter = 0;
  33. for (int i = 0; i < 2; i++)
  34. {
  35. for (int j = 0; j < 3; j++) {
  36. Border border = new Border();
  37. border.BorderBrush = Brushes.Gray;
  38. border.BorderThickness = new Thickness(1);
  39. border.Margin = new Thickness(10);
  40. border.Background = Brushes.White;
  41. ProductGrid.Children.Add(border);
  42. Grid.SetRow(border, i);
  43. Grid.SetColumn(border, j);
  44. StackPanel stackPanel = new StackPanel();
  45. border.Child = stackPanel;
  46. //< Image Source = "/WPF01;component/Товары автосервиса/E9308929.jpg" Height = "129" Margin = "20,10,20,0" />
  47. Image image = new Image();
  48. image.Height = 130;
  49. stackPanel.Children.Add(image);
  50. Label l1 = new Label();
  51. l1.Content = products[productCouter].Title;
  52. l1.FontSize = 10;
  53. l1.Foreground = Brushes.DarkMagenta;
  54. l1.Padding = new Thickness(0);
  55. l1.Margin = new Thickness(0);
  56. l1.HorizontalContentAlignment = HorizontalAlignment.Center;
  57. stackPanel.Children.Add(l1);
  58. Label l2 = new Label();
  59. l2.Content = products[productCouter].Cost;
  60. stackPanel.Children.Add(l2);
  61. if (products[productCouter].IsActive == false) {
  62. Label l3 = new Label();
  63. l3.Content = "неактивен";
  64. stackPanel.Children.Add(l3);
  65. border.Background = Brushes.LightGray;
  66. }
  67. productCouter++;
  68. }
  69. }
  70. }
  71. }
  72. }