瀏覽代碼

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

МухинаЛВ 1 月之前
父節點
當前提交
5f6acd625d

+ 25 - 0
AvaloniaApplication10.sln

@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.10.35027.167
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvaloniaApplication10", "AvaloniaApplication10\AvaloniaApplication10.csproj", "{F086DED3-903B-4D1A-BADA-38A84FF9F3B5}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{F086DED3-903B-4D1A-BADA-38A84FF9F3B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{F086DED3-903B-4D1A-BADA-38A84FF9F3B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{F086DED3-903B-4D1A-BADA-38A84FF9F3B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{F086DED3-903B-4D1A-BADA-38A84FF9F3B5}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {C00B2CCA-044D-4282-86E5-536E02FF1E3C}
+	EndGlobalSection
+EndGlobal

+ 15 - 0
AvaloniaApplication10/App.axaml

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

+ 29 - 0
AvaloniaApplication10/App.axaml.cs

@@ -0,0 +1,29 @@
+using Avalonia;
+using Avalonia.Controls.ApplicationLifetimes;
+using Avalonia.Markup.Xaml;
+using AvaloniaApplication10.ViewModels;
+using AvaloniaApplication10.Views;
+
+namespace AvaloniaApplication10
+{
+    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
+                {
+                    DataContext = new MainWindowViewModel(),
+                };
+            }
+
+            base.OnFrameworkInitializationCompleted();
+        }
+    }
+}

二進制
AvaloniaApplication10/Assets/avalonia-logo.ico


+ 26 - 0
AvaloniaApplication10/AvaloniaApplication10.csproj

@@ -0,0 +1,26 @@
+<Project Sdk="Microsoft.NET.Sdk">
+  <PropertyGroup>
+    <OutputType>WinExe</OutputType>
+    <TargetFramework>net8.0</TargetFramework>
+    <Nullable>enable</Nullable>
+    <BuiltInComInteropSupport>true</BuiltInComInteropSupport>
+    <ApplicationManifest>app.manifest</ApplicationManifest>
+    <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <Folder Include="Models\" />
+    <AvaloniaResource Include="Assets\**" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Avalonia" Version="11.1.0" />
+    <PackageReference Include="Avalonia.Desktop" Version="11.1.0" />
+    <PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.0" />
+    <PackageReference Include="Avalonia.Fonts.Inter" Version="11.1.0" />
+    <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
+    <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.0" />
+    <PackageReference Include="Avalonia.ReactiveUI" Version="11.1.0" />
+    <PackageReference Include="MessageBox.Avalonia" Version="3.1.6" />
+  </ItemGroup>
+</Project>

+ 24 - 0
AvaloniaApplication10/Program.cs

@@ -0,0 +1,24 @@
+using Avalonia;
+using Avalonia.ReactiveUI;
+using System;
+
+namespace AvaloniaApplication10
+{
+    internal sealed 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()
+                .UseReactiveUI();
+    }
+}

+ 34 - 0
AvaloniaApplication10/ViewLocator.cs

@@ -0,0 +1,34 @@
+using Avalonia.Controls;
+using Avalonia.Controls.Templates;
+using AvaloniaApplication10.ViewModels;
+using System;
+
+namespace AvaloniaApplication10
+{
+    public class ViewLocator : IDataTemplate
+    {
+
+        public Control? Build(object? data)
+        {
+            if (data is null)
+                return null;
+
+            var name = data.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal);
+            var type = Type.GetType(name);
+
+            if (type != null)
+            {
+                var control = (Control)Activator.CreateInstance(type)!;
+                control.DataContext = data;
+                return control;
+            }
+
+            return new TextBlock { Text = "Not Found: " + name };
+        }
+
+        public bool Match(object? data)
+        {
+            return data is ViewModelBase;
+        }
+    }
+}

+ 41 - 0
AvaloniaApplication10/ViewModels/MainWindowViewModel.cs

@@ -0,0 +1,41 @@
+using Avalonia.Controls;
+using ReactiveUI;
+
+namespace AvaloniaApplication10.ViewModels
+{
+    public class MainWindowViewModel : ViewModelBase
+    {
+        UserControl _us = new Page1();
+
+        public UserControl Us {
+            get => _us;
+            set => this.RaiseAndSetIfChanged(ref _us, value); 
+        }
+        
+
+         Page1ViewModel _page1VM = new Page1ViewModel();
+
+        public Page1ViewModel Page1VM 
+        { 
+            get => _page1VM; 
+            set => _page1VM = value; 
+        }
+        public Page2ViewModel Page2VM 
+        { 
+            get => page2VM; 
+            set => page2VM = value; 
+        }
+
+        Page2ViewModel page2VM = new Page2ViewModel();
+
+        public void ToPage2()
+        {
+            Us = new Page2();
+        }
+
+        public void ToPage1()
+        {
+            Us = new Page1();
+        }
+    }
+}

+ 39 - 0
AvaloniaApplication10/ViewModels/Page1ViewModel.cs

@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using MsBox.Avalonia;
+using MsBox.Avalonia.Enums;
+using ReactiveUI;
+
+namespace AvaloniaApplication10.ViewModels
+{
+	public class Page1ViewModel : ReactiveObject
+	{
+		string _message = "Äîáðî ïîæàëîâàòü";
+
+        public string Message 
+		{ 
+			get => _message; 
+			set => this.RaiseAndSetIfChanged(ref _message, value); 
+		}
+
+		public async void changeMessage()
+		{
+			Message = "Ïðèâåò, ìèð";
+			ButtonResult result =  await MessageBoxManager.GetMessageBoxStandard("Îêíî ïîêàçà ñîîáùåíèÿ","Ìû íàæàëè íà êíîïêó",ButtonEnum.YesNo).ShowAsync();
+
+			switch(result)
+			{
+				case ButtonResult.Yes:
+				{
+                        await MessageBoxManager.GetMessageBoxStandard("Îêíî ïîêàçà ñîîáùåíèÿ", "Äà", ButtonEnum.Ok).ShowAsync();
+						break;
+					}
+					case ButtonResult.No:
+					{
+                        await MessageBoxManager.GetMessageBoxStandard("Îêíî ïîêàçà ñîîáùåíèÿ", "íåò", ButtonEnum.Ok).ShowAsync();
+						break;
+					}
+			}
+		}
+    }
+}

+ 10 - 0
AvaloniaApplication10/ViewModels/Page2ViewModel.cs

@@ -0,0 +1,10 @@
+using System;
+using System.Collections.Generic;
+using ReactiveUI;
+
+namespace AvaloniaApplication10.ViewModels
+{
+	public class Page2ViewModel : ReactiveObject
+	{
+	}
+}

+ 8 - 0
AvaloniaApplication10/ViewModels/ViewModelBase.cs

@@ -0,0 +1,8 @@
+using ReactiveUI;
+
+namespace AvaloniaApplication10.ViewModels
+{
+    public class ViewModelBase : ReactiveObject
+    {
+    }
+}

+ 23 - 0
AvaloniaApplication10/Views/MainWindow.axaml

@@ -0,0 +1,23 @@
+<Window xmlns="https://github.com/avaloniaui"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:vm="using:AvaloniaApplication10.ViewModels"
+        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="AvaloniaApplication10.Views.MainWindow"
+        x:DataType="vm:MainWindowViewModel"
+        Icon="/Assets/avalonia-logo.ico"
+        Title="AvaloniaApplication10" FontSize="32">
+
+    <Design.DataContext>
+        <!-- This only sets the DataContext for the previewer in an IDE,
+             to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
+        <vm:MainWindowViewModel/>
+    </Design.DataContext>
+
+   <StackPanel>
+	   <TextBlock>Главное окно</TextBlock>
+	   <UserControl Content="{Binding Us}"></UserControl>
+   </StackPanel>
+
+</Window>

+ 12 - 0
AvaloniaApplication10/Views/MainWindow.axaml.cs

@@ -0,0 +1,12 @@
+using Avalonia.Controls;
+
+namespace AvaloniaApplication10.Views
+{
+    public partial class MainWindow : Window
+    {
+        public MainWindow()
+        {
+            InitializeComponent();
+        }
+    }
+}

+ 14 - 0
AvaloniaApplication10/Views/Page1.axaml

@@ -0,0 +1,14 @@
+<UserControl xmlns="https://github.com/avaloniaui"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+             xmlns:vm="using:AvaloniaApplication10.ViewModels"
+			 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+			 x:DataType="vm:MainWindowViewModel"
+             x:Class="AvaloniaApplication10.Page1">
+	<StackPanel>
+		<TextBlock Text="{Binding Page1VM.Message}"></TextBlock>
+		<Button Command="{Binding Page1VM.changeMessage}">Показать сообщение</Button>
+		<Button Command="{Binding ToPage2}">Перейти на страницу 2</Button>
+	</StackPanel>
+</UserControl>

+ 13 - 0
AvaloniaApplication10/Views/Page1.axaml.cs

@@ -0,0 +1,13 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+
+namespace AvaloniaApplication10;
+
+public partial class Page1 : UserControl
+{
+    public Page1()
+    {
+        InitializeComponent();
+    }
+}

+ 14 - 0
AvaloniaApplication10/Views/Page2.axaml

@@ -0,0 +1,14 @@
+<UserControl xmlns="https://github.com/avaloniaui"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+			 xmlns:vm="using:AvaloniaApplication10.ViewModels"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+			 x:DataType="vm:MainWindowViewModel"
+             x:Class="AvaloniaApplication10.Page2">
+	<StackPanel>
+		<TextBlock>Вы перешли на страницу 2</TextBlock>
+	<Button Command="{Binding ToPage1}">Вернуться на страницу 1</Button>
+	</StackPanel>
+	
+</UserControl>

+ 13 - 0
AvaloniaApplication10/Views/Page2.axaml.cs

@@ -0,0 +1,13 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+
+namespace AvaloniaApplication10;
+
+public partial class Page2 : UserControl
+{
+    public Page2()
+    {
+        InitializeComponent();
+    }
+}

+ 18 - 0
AvaloniaApplication10/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="AvaloniaApplication10.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>