/
Landilf
/
2413_Ryumin_CourseWork
Обзор
Документация
Войти
/
Landilf
/
2413_Ryumin_CourseWork
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
CourseWork/GUI/Views/ConfirmationView.axaml.cs
81 строка
3 KB
Landilf
add project
27 янв 2026, 13:57
27 янв 2026, 13:57
753b3e7
Код
Авторство
О чём код?
using Avalonia; using Avalonia.Controls; using Avalonia.Media; using GUI.ViewModels; using System.Globalization; namespace GUI.Views; public partial class ConfirmationView : UserControl { /// <summary> /// Конструктор. /// </summary> public ConfirmationView() { InitializeComponent(); } /// <summary> /// Обработчик смены DataContext. /// </summary> /// <param name="parEventArgs">Аргументы события.</param> protected override void OnDataContextChanged(EventArgs parEventArgs) { base.OnDataContextChanged(parEventArgs); if (DataContext is ConfirmationViewModel vm) { vm.PropertyChanged += (s, e) => InvalidateVisual(); } } /// <summary> /// Отрисовывает экран подтверждения. /// </summary> /// <param name="parContext">Контекст рисования.</param> public override void Render(DrawingContext parContext) { base.Render(parContext); if (DataContext is not ConfirmationViewModel vm) { return; } // Полупрозрачный фон поверх всего parContext.DrawRectangle(new SolidColorBrush(Color.Parse("#AAFDE9D9")), null, Bounds); double centerX = Bounds.Width / 2; double centerY = Bounds.Height / 2; var brush = new SolidColorBrush(Color.Parse("#D93025")); // Подготовка текста сообщения с переносом строк var msg = new FormattedText(vm.Message, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial", FontStyle.Normal, FontWeight.Bold), 24, brush) { MaxTextWidth = 500, TextAlignment = TextAlignment.Center }; // Плашка диалога (динамическая высота в зависимости от текста) double dialogHeight = Math.Max(250, msg.Height + 150); var dialogRect = new Rect(centerX - 300, centerY - dialogHeight / 2, 600, dialogHeight); parContext.DrawRectangle(new SolidColorBrush(Color.Parse("#FDE9D9")), new Pen(brush, 2), dialogRect); parContext.DrawText(msg, new Point(centerX - 250, dialogRect.Y + 40)); for (int i = 0; i < vm.MenuItems.Count; i++) { var item = vm.MenuItems[i]; bool isSelected = i == vm.SelectedIndex; var rect = new Rect(centerX - 220 + i * 240, dialogRect.Bottom - 80, 200, 50); if (isSelected) { parContext.DrawRectangle(new SolidColorBrush(Color.Parse("#F4CCCC")), new Pen(new SolidColorBrush(Color.Parse("#EA9999")), 2), rect); } else { parContext.DrawRectangle(null, new Pen(new SolidColorBrush(Color.Parse("#EA9999")), 1), rect); } var text = new FormattedText(item.Title, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial", FontStyle.Normal, isSelected ? FontWeight.Bold : FontWeight.Normal), 20, brush); parContext.DrawText(text, new Point(rect.X + (rect.Width - text.Width) / 2, rect.Y + (rect.Height - text.Height) / 2)); } } }