Demo/Demo3/Catalog.axaml.cs
2024-12-27 13:32:41 +03:00

49 lines
1.5 KiB
C#

using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Media.Imaging;
using Demo3.Models;
using System.Collections.ObjectModel;
using System.Linq;
namespace Demo3;
public partial class Catalog : Window
{
public Catalog()
{
ObservableCollection<ProductPresenter> presenters;
InitializeComponent();
using var context = new ParsingdbContext();
var dataSource = context.Products.Select(product => new ProductPresenter
{
Productarticlenumber = product.Productarticlenumber,
Productname = product.Productname,
Productdescription = product.Productdescription,
Productcategory = product.Productcategory,
Productcost = product.Productcost,
Productdiscountamount = product.Productdiscountamount,
Productdiscountamountmax = product.Productdiscountamountmax,
Productmanufacturer = product.Productmanufacturer,
Productphoto = product.Productphoto,
Productquantityinstock = product.Productquantityinstock,
Productstatus = product.Productstatus
});
var products = new ObservableCollection<ProductPresenter>(dataSource);
ProductList.ItemsSource = products;
}
public class ProductPresenter() : Product
{
Bitmap? Image
{
get
{
try
{
return new Bitmap(Productphoto);
}
catch { return null; }
}
}
}
}