newDemoAvaloniaVal/AvaloniaValidation/MainWindow.axaml.cs
2025-01-28 22:01:04 +03:00

68 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Media.Imaging;
using AvaloniaValidation.Models;
namespace AvaloniaValidation;
public partial class MainWindow : Window
{
private ObservableCollection<EventPresenter> events = new ObservableCollection<EventPresenter>();
public MainWindow()
{
InitializeComponent();
using var context = new User1Context();
var dataSourceEvent = context.Events.Select(it => new EventPresenter
{
Sobitie = it.Sobitie,
Date = it.Date,
Days = it.Days,
City = it.City,
Photo = it.Photo
}).ToList();
foreach (var eventItem in dataSourceEvent)
{
events.Add(eventItem);
}
EventListBox.ItemsSource = events;
}
public class EventPresenter : Event
{
public Bitmap? Image
{
get
{
try
{
string path = Path.Combine(AppContext.BaseDirectory, Photo);
if (File.Exists(path))
{
return new Bitmap(path);
}
return null;
}
catch
{
return null;
}
}
}
}
private void Registration(object? sender, RoutedEventArgs e)
{
new Registration().ShowDialog(this);
}
}