Modules
This commit is contained in:
10
ModuleWeather/MainWindow.axaml
Normal file
10
ModuleWeather/MainWindow.axaml
Normal file
@@ -0,0 +1,10 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
x:Class="ModuleWeather.WeatherView">
|
||||
<StackPanel Margin="20" Spacing="10" Background="#2b2b2b">
|
||||
<TextBlock Name="StatusText" Text="Введите город:" Foreground="White"/>
|
||||
<TextBox Name="CityInput" Watermark="Например: Москва"/>
|
||||
<Button Content="Узнать погоду" Click="GetWeatherButton_Click"
|
||||
HorizontalAlignment="Stretch" HorizontalContentAlignment="Center"/>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
22
ModuleWeather/MainWindow.axaml.cs
Normal file
22
ModuleWeather/MainWindow.axaml.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace ModuleWeather;
|
||||
|
||||
public partial class WeatherView : UserControl
|
||||
{
|
||||
public WeatherView() => InitializeComponent();
|
||||
|
||||
private void GetWeatherButton_Click(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
var city = this.FindControl<TextBox>("CityInput")?.Text;
|
||||
var status = this.FindControl<TextBlock>("StatusText");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(city)) {
|
||||
status.Text = "Ошибка: введите город";
|
||||
return;
|
||||
}
|
||||
status.Text = $"В городе {city} сейчас +20°C"; // Тут могла быть логика API
|
||||
}
|
||||
}
|
||||
40
ModuleWeather/Module.cs
Normal file
40
ModuleWeather/Module.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace ModuleWeather;
|
||||
|
||||
public class WeatherModule
|
||||
{
|
||||
public string Name => "Прогноз Погоды";
|
||||
|
||||
public string[] GetCommands() => new[] { "ShowWeather", "Ping" };
|
||||
|
||||
public object Execute(string command, object[] args)
|
||||
{
|
||||
switch (command)
|
||||
{
|
||||
case "ShowWeather":
|
||||
// args[0] — это родительское окно из Ядра
|
||||
var parentWindow = args != null && args.Length > 0 ? args[0] as Window : null;
|
||||
|
||||
var win = new Window
|
||||
{
|
||||
Title = "Окно Погоды",
|
||||
Content = new WeatherView(), // Вставляем наш контрол
|
||||
Width = 350,
|
||||
Height = 250,
|
||||
WindowStartupLocation = WindowStartupLocation.CenterOwner
|
||||
};
|
||||
|
||||
if (parentWindow != null) win.Show(parentWindow);
|
||||
else win.Show();
|
||||
|
||||
return "Окно открыто успешно";
|
||||
|
||||
case "Ping":
|
||||
return "Pong! Модуль погоды активен.";
|
||||
|
||||
default:
|
||||
return "Команда не найдена";
|
||||
}
|
||||
}
|
||||
}
|
||||
24
ModuleWeather/ModuleWeather.csproj
Normal file
24
ModuleWeather/ModuleWeather.csproj
Normal file
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\VisionAsist.SDK\VisionAsist.SDK.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="MainWindow.axaml.cs">
|
||||
<DependentUpon>MainWindow.axaml</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="11.3.12" />
|
||||
<PackageReference Include="Avalonia.Desktop" Version="11.3.12" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user