demo2023/demo_2023/MainWindow.axaml.cs

77 lines
1.8 KiB
C#
Raw Normal View History

2025-01-28 12:20:48 +00:00
using System;
2025-01-22 13:34:31 +00:00
using System.Collections.Generic;
2025-01-28 12:20:48 +00:00
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
2025-01-22 13:34:31 +00:00
using Avalonia.Controls;
using Avalonia.Interactivity;
2025-01-28 12:20:48 +00:00
using Avalonia.Media.Imaging;
2025-01-22 13:34:31 +00:00
using demo_2023.Models;
2025-01-28 18:00:31 +00:00
namespace demo_2023
2025-01-22 13:34:31 +00:00
{
2025-01-28 18:00:31 +00:00
public partial class MainWindow : Window
2025-01-22 13:34:31 +00:00
{
2025-01-28 18:00:31 +00:00
private ObservableCollection<EventPresenter> events = new ObservableCollection<EventPresenter>();
2025-01-28 12:20:48 +00:00
2025-01-28 18:00:31 +00:00
public MainWindow()
{
InitializeComponent();
2025-01-28 12:20:48 +00:00
2025-01-28 18:00:31 +00:00
using var context = new User15Context();
2025-01-28 12:20:48 +00:00
2025-01-28 18:00:31 +00:00
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
2025-01-28 12:20:48 +00:00
{
2025-01-28 18:00:31 +00:00
public Bitmap? Image
2025-01-28 12:20:48 +00:00
{
2025-01-28 18:00:31 +00:00
get
2025-01-28 12:20:48 +00:00
{
2025-01-28 18:00:31 +00:00
try
{
string absolutePath = Path.Combine(AppContext.BaseDirectory, Photo);
if (File.Exists(absolutePath))
{
return new Bitmap(absolutePath);
}
return null;
}
catch
{
return null;
}
2025-01-28 12:20:48 +00:00
}
}
}
2025-01-28 18:00:31 +00:00
private void Jury_reg(object? sender, RoutedEventArgs e)
{
new Additem().ShowDialog(this);
}
2025-01-22 13:34:31 +00:00
}
2025-01-28 18:00:31 +00:00
}