Загрузка данных
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TravelDocumentsOrganizer.MainPage"
BackgroundColor="#F3F4F6">
<ScrollView>
<VerticalStackLayout Padding="20" Spacing="15">
<Label
Text="Органайзер документов"
FontSize="30"
FontAttributes="Bold"
HorizontalOptions="Center"
TextColor="#111827"/>
<Frame
BackgroundColor="White"
CornerRadius="20"
Padding="15"
HasShadow="True">
<VerticalStackLayout Spacing="12">
<Picker
x:Name="typePicker"
Title="Тип документа">
<Picker.Items>
<x:String>Паспорт</x:String>
<x:String>Билет</x:String>
<x:String>Виза</x:String>
<x:String>Страховка</x:String>
</Picker.Items>
</Picker>
<Entry
x:Name="numberEntry"
Placeholder="Серия и номер"/>
<Entry
x:Name="countryEntry"
Placeholder="Страна"/>
<DatePicker
x:Name="datePicker"/>
<Editor
x:Name="descriptionEditor"
Placeholder="Описание"
HeightRequest="100"/>
<Button
Text="Добавить документ"
BackgroundColor="#2563EB"
TextColor="White"
CornerRadius="12"
HeightRequest="50"
Clicked="OnAddClicked"/>
</VerticalStackLayout>
</Frame>
<Label
Text="Список документов"
FontSize="24"
FontAttributes="Bold"
TextColor="#111827"/>
<VerticalStackLayout
x:Name="documentsLayout"
Spacing="15"/>
</VerticalStackLayout>
</ScrollView>
</ContentPage>
namespace TravelDocumentsOrganizer;
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private void OnAddClicked(object sender, EventArgs e)
{
string type = typePicker.SelectedItem?.ToString();
string number = numberEntry.Text;
string country = countryEntry.Text;
string description = descriptionEditor.Text;
string date = datePicker.Date.ToShortDateString();
if (string.IsNullOrWhiteSpace(type) ||
string.IsNullOrWhiteSpace(number) ||
string.IsNullOrWhiteSpace(country))
{
DisplayAlert(
"Ошибка",
"Заполните обязательные поля",
"OK");
return;
}
Label infoLabel = new Label
{
Text =
$"Тип: {type}\n" +
$"Номер: {number}\n" +
$"Страна: {country}\n" +
$"Дата: {date}\n\n" +
$"{description}",
FontSize = 16,
TextColor = Colors.Black
};
Button deleteButton = new Button
{
Text = "Удалить",
BackgroundColor = Colors.Red,
TextColor = Colors.White,
CornerRadius = 10
};
VerticalStackLayout layout = new VerticalStackLayout
{
Spacing = 10
};
layout.Children.Add(infoLabel);
layout.Children.Add(deleteButton);
Frame card = new Frame
{
BackgroundColor = Colors.White,
CornerRadius = 20,
Padding = 15,
HasShadow = true,
Content = layout
};
deleteButton.Clicked += (s, args) =>
{
documentsLayout.Children.Remove(card);
};
documentsLayout.Children.Add(card);
typePicker.SelectedIndex = -1;
numberEntry.Text = "";
countryEntry.Text = "";
descriptionEditor.Text = "";
}
}