فهرست منبع

Добавьте файлы проекта.

МухинаЛВ 6 ماه پیش
والد
کامیت
a853e40ebd

+ 25 - 0
AvaloniaApplication2.sln

@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.6.33829.357
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvaloniaApplication2", "AvaloniaApplication2\AvaloniaApplication2.csproj", "{2EF5679E-F9C8-475F-8D77-C8FDD57AEF9C}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{2EF5679E-F9C8-475F-8D77-C8FDD57AEF9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{2EF5679E-F9C8-475F-8D77-C8FDD57AEF9C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{2EF5679E-F9C8-475F-8D77-C8FDD57AEF9C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{2EF5679E-F9C8-475F-8D77-C8FDD57AEF9C}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {730423EB-AE70-4CC0-91CA-020153E0B3E4}
+	EndGlobalSection
+EndGlobal

+ 10 - 0
AvaloniaApplication2/App.axaml

@@ -0,0 +1,10 @@
+<Application xmlns="https://github.com/avaloniaui"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             x:Class="AvaloniaApplication2.App"
+             RequestedThemeVariant="Default">
+             <!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
+
+    <Application.Styles>
+        <FluentTheme />
+    </Application.Styles>
+</Application>

+ 24 - 0
AvaloniaApplication2/App.axaml.cs

@@ -0,0 +1,24 @@
+using Avalonia;
+using Avalonia.Controls.ApplicationLifetimes;
+using Avalonia.Markup.Xaml;
+
+namespace AvaloniaApplication2
+{
+    public partial class App : Application
+    {
+        public override void Initialize()
+        {
+            AvaloniaXamlLoader.Load(this);
+        }
+
+        public override void OnFrameworkInitializationCompleted()
+        {
+            if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
+            {
+                desktop.MainWindow = new MainWindow();
+            }
+
+            base.OnFrameworkInitializationCompleted();
+        }
+    }
+}

+ 19 - 0
AvaloniaApplication2/AvaloniaApplication2.csproj

@@ -0,0 +1,19 @@
+<Project Sdk="Microsoft.NET.Sdk">
+  <PropertyGroup>
+    <OutputType>WinExe</OutputType>
+    <TargetFramework>net7.0</TargetFramework>
+    <Nullable>enable</Nullable>
+    <BuiltInComInteropSupport>true</BuiltInComInteropSupport>
+    <ApplicationManifest>app.manifest</ApplicationManifest>
+    <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Avalonia" Version="11.0.10" />
+    <PackageReference Include="Avalonia.Desktop" Version="11.0.10" />
+    <PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.10" />
+    <PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.10" />
+    <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
+    <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.10" />
+  </ItemGroup>
+</Project>

+ 44 - 0
AvaloniaApplication2/MainWindow.axaml

@@ -0,0 +1,44 @@
+<Window xmlns="https://github.com/avaloniaui"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+        x:Class="AvaloniaApplication2.MainWindow"
+        Title="AvaloniaApplication2" FontSize="36">
+	<Grid>
+		<StackPanel HorizontalAlignment="Center">
+			<StackPanel Orientation="Horizontal" >
+				<StackPanel Margin="10">
+					<TextBlock>Введите название страны:</TextBlock>
+					<TextBox Name="tbName"></TextBox>
+				</StackPanel>
+				<StackPanel Margin="10">
+					<TextBlock>Введите столицу:</TextBlock>
+					<TextBox Name="tbCapital"></TextBox>
+				</StackPanel>
+			</StackPanel>
+			<StackPanel Orientation="Horizontal">
+				<RadioButton Name="rbM" FontSize ="36" Margin="10">Монархия</RadioButton>
+				<RadioButton Name="rbK" FontSize ="36" Margin="10">Конституция</RadioButton>
+				<RadioButton Name="rbD" FontSize ="36" Margin="10">Демократия</RadioButton>
+			</StackPanel>
+			<StackPanel Orientation="Horizontal">
+				<ComboBox Name="cbContinent" FontSize ="36" SelectedIndex="0">
+					<ComboBoxItem IsEnabled="false">Выберите материк</ComboBoxItem>
+					<ComboBoxItem>Евразия</ComboBoxItem>
+					<ComboBoxItem>Америка</ComboBoxItem>
+					<ComboBoxItem>Африка</ComboBoxItem>
+				</ComboBox>
+				<CheckBox Name="cbNATO" FontSize ="36" Margin="10">Страна НАТО</CheckBox>
+			</StackPanel>
+			<TextBlock>Выберите религии:</TextBlock>
+			<ListBox SelectionMode="Multiple" FontSize ="36" Name="lbReligions">
+				<TextBlock FontSize ="36">Ислам</TextBlock>
+				<TextBlock FontSize ="36">Христианство</TextBlock>
+				<TextBlock FontSize ="36">Буддизм</TextBlock>
+			</ListBox>			
+			<Button Click="WriteFile" Margin="10">Записать в файл</Button>
+			<TextBlock Name="ShowMessage" Foreground="Red"></TextBlock>
+		</StackPanel>		
+	</Grid>
+</Window>

+ 76 - 0
AvaloniaApplication2/MainWindow.axaml.cs

@@ -0,0 +1,76 @@
+using Avalonia.Controls;
+using Avalonia.Interactivity;
+using Avalonia.Markup.Xaml.MarkupExtensions;
+using System.IO;
+
+namespace AvaloniaApplication2
+{
+    // структура
+    public struct Countries
+    {
+        public string name; // название страны
+        public string capital; // столица
+        public string form; // форма правления
+        public string continent; // материк
+        public string religions; // религии
+        public bool isNATO; // является ли членом НАТО
+    }
+    public partial class MainWindow : Window
+    {
+        public MainWindow()
+        {
+            InitializeComponent();
+           // cbContinent.SelectedIndex = 0;
+        }
+
+        // обработчик события Click для записи в файл
+        private void WriteFile(object sender, RoutedEventArgs e)
+        {
+            Countries country = new Countries(); // создание объекта структуры
+
+            // заполнение полей структуры
+            country.name = tbName.Text; // заполнение названия страны из текстового поля
+            country.capital = tbCapital.Text; // заполнение столицы из текстового поля
+
+            // в зависимости от того, какая радиокнопка активна, происходит запись формы правления
+            if (rbM.IsChecked == true) country.form = "Монархия";
+            if (rbK.IsChecked == true) country.form = "Конституция";
+            if (rbD.IsChecked == true) country.form = "Демократия";
+
+            // если флажок выбран, то записываем принадлежность страны к НАТО
+            if (cbNATO.IsChecked == true) country.isNATO = true;
+            else country.isNATO = false;
+
+            // записываем континент в зависимости от выбранного значения в списке, ориентируясь на индекс выбранного значения (значения начинаются с индекса 0)
+            switch (cbContinent.SelectedIndex)
+            {
+                case 1:
+                    country.continent = "Евразия";
+                    break;
+                case 2:
+                    country.continent = "Америка";
+                    break;
+                case 3:
+                    country.continent = "Африка";
+                    break;
+            }
+
+            
+            string religions = "";  // строка для формирования сведений о регилиях в стране
+
+            // пробегаемся по всему списку выбранных религий (так как у списка настроен множественный выбор при условии зажатия Ctrl)
+            foreach (TextBlock item in lbReligions.SelectedItems)
+            {
+                religions += religions + item.Text + ", "; // добавляем религию в строку яерез запятую
+            }
+            country.religions = religions;
+
+            // запись а файл
+            using (StreamWriter sw = new StreamWriter("users.csv",true,System.Text.Encoding.UTF8))
+            {
+                sw.WriteLine(country.name + ";" + country.capital + ";" + country.continent + ";" + country.form + ";" + country.religions + ";" + country.isNATO);
+                ShowMessage.Text = "Запись добавлена";
+            }
+        }       
+    }
+}

+ 22 - 0
AvaloniaApplication2/Program.cs

@@ -0,0 +1,22 @@
+using Avalonia;
+using System;
+
+namespace AvaloniaApplication2
+{
+    internal class Program
+    {
+        // Initialization code. Don't use any Avalonia, third-party APIs or any
+        // SynchronizationContext-reliant code before AppMain is called: things aren't initialized
+        // yet and stuff might break.
+        [STAThread]
+        public static void Main(string[] args) => BuildAvaloniaApp()
+            .StartWithClassicDesktopLifetime(args);
+
+        // Avalonia configuration, don't remove; also used by visual designer.
+        public static AppBuilder BuildAvaloniaApp()
+            => AppBuilder.Configure<App>()
+                .UsePlatformDetect()
+                .WithInterFont()
+                .LogToTrace();
+    }
+}

+ 18 - 0
AvaloniaApplication2/app.manifest

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
+  <!-- This manifest is used on Windows only.
+       Don't remove it as it might cause problems with window transparency and embedded controls.
+       For more details visit https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests -->
+  <assemblyIdentity version="1.0.0.0" name="AvaloniaApplication2.Desktop"/>
+
+  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
+    <application>
+      <!-- A list of the Windows versions that this application has been tested on
+           and is designed to work with. Uncomment the appropriate elements
+           and Windows will automatically select the most compatible environment. -->
+
+      <!-- Windows 10 -->
+      <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
+    </application>
+  </compatibility>
+</assembly>