```MainWindow.xaml.cs```
```
using cs_mysql_connection.Models;
using System.IO.Packaging;
using System.Text;
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;
using MySqlConnector;
using Dapper;


namespace cs_mysql_connection
{

   
    public partial class MainWindow : Window

    {
        public List<Product> ProductList { get; set; }
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;
            Globals.DataProvider = new DBDataProvider();
            ProductList = (List<Product>?)Globals.DataProvider.getProduct();

        }
        static string connectionString = "Server=kolei.ru; User ID=sbahtina; Password=010906; Database=sbahtina";
    }





}
```

```MainWindow.cs```

```
<Window x:Class="cs_mysql_connection.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:cs_mysql_connection"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Window.Resources>
        <BitmapImage 
        x:Key='defaultImage' 
        UriSource='./img/tire_0.jpg' />
    </Window.Resources>
    <ListBox
    ItemsSource="{Binding ProductList}"
    ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
>
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel 
                HorizontalAlignment="Center" />
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>

        <ListBox.ItemTemplate>
            <DataTemplate>
                <Border 
            BorderThickness="1" 
            BorderBrush="Black" 
            CornerRadius="5">

                    <Grid 
    Margin="10" 
    HorizontalAlignment="Stretch">

                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="64"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="auto"/>
                        </Grid.ColumnDefinitions>

                        <Image
    Width="64" 
    Height="64"
    Source="{Binding ImageBitmap,TargetNullValue={StaticResource defaultImage}}" />
                        <StackPanel
    Grid.Column="1"
    Margin="5"
    Orientation="Vertical">

                            <TextBlock 
        Text="{Binding Title}"/>

                            <TextBlock 
        Text="{Binding ArticleNumber}"/>
                        </StackPanel>
                        <TextBlock 
    Grid.Column="2"
    Text="{Binding ID}"/>

                    </Grid>

                </Border>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</Window>
```

```Product.cs```
```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace cs_mysql_connection.Models
{
    public class Product
    {
        public int ID { get; set; }
        public required string Title { get; set; }
        public string? Image { get; set; }
        public int ProductTypeID { get; set; }
        public required string ProductTypeTitle { get; set; }
        public required string ArticleNumber { get; set; }
        public double? MaterialCost { get; set; }
        public string? MaterialString { get; set; }
        public Uri? ImageBitmap
        {
            get
            {
                var imageName = Environment.CurrentDirectory + (Image ?? "");
                return System.IO.File.Exists(imageName) ? new Uri(imageName) : null;
            }
        }

    }
}
```

```IDataProvider.cs```
```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace cs_mysql_connection.Models
{
    public interface IDataProvider
    {
        IEnumerable<Product> getProduct();
    }
}
```

``` BDataProvider.cs```
```
using MySqlConnector;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySqlConnector;
using Dapper;

namespace cs_mysql_connection.Models
{
    public class DBDataProvider : IDataProvider
    {
        static string connectionString = "Server=kolei.ru; User ID=sbahtina; Password=010906; Database=sbahtina";

        public IEnumerable<Product> getProduct()
        {
            using (MySqlConnection db = new MySqlConnection(connectionString))
            {
                return db.Query<Product>(
                    "SELECT * FROM ProductView")
                .ToList();
            }
        }
    }
}
```
```Globals.cs```

```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace cs_mysql_connection.Models
{
    class Globals
    {
        public static IDataProvider DataProvider;
    }
}
```
![](./img/1.png)