Add settings func
This commit is contained in:
@@ -2,10 +2,22 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using VisionAsist.Models;
|
||||
using VisionAsist.Views;
|
||||
|
||||
namespace VisionAsist.ViewModels;
|
||||
|
||||
public partial class MainWindowViewModel : ViewModelBase
|
||||
{
|
||||
[RelayCommand]
|
||||
private void Settingse()
|
||||
{
|
||||
new Settings
|
||||
{
|
||||
DataContext = new SettingsViewModel()
|
||||
}.Show();
|
||||
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
private bool isListening;
|
||||
[ObservableProperty]
|
||||
|
||||
@@ -1,6 +1,44 @@
|
||||
namespace VisionAsist.ViewModels;
|
||||
using System;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using System.Collections.ObjectModel;
|
||||
namespace VisionAsist.ViewModels;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
public class ModuleItem
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public IRelayCommand SettingsCommand { get; set; }
|
||||
}
|
||||
|
||||
public class SettingsViewModel : ViewModelBase
|
||||
{
|
||||
string Plugin = Path.Combine(AppContext.BaseDirectory, "Modules");
|
||||
public ObservableCollection<ModuleItem> Modules { get; } = new();
|
||||
|
||||
public SettingsViewModel()
|
||||
{
|
||||
string[] folderNames = new DirectoryInfo(Plugin)
|
||||
.GetDirectories()
|
||||
.Select(d => d.Name)
|
||||
.ToArray();
|
||||
foreach (string folderName in folderNames)
|
||||
{
|
||||
AddModule(folderName);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddModule(string name)
|
||||
{
|
||||
Modules.Add(new ModuleItem
|
||||
{
|
||||
Name = name,
|
||||
SettingsCommand = new RelayCommand(() => OpenSettings(name))
|
||||
});
|
||||
}
|
||||
|
||||
private void OpenSettings(string moduleName)
|
||||
{
|
||||
Console.WriteLine($"Нажата кнопка модуля: {moduleName}");
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@
|
||||
</Design.DataContext>
|
||||
<StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="10">
|
||||
<Button Content="Настройки"/>
|
||||
<Button Content="Настройки" Command="{Binding SettingseCommand}"/>
|
||||
<ToggleButton IsChecked="{Binding IsListening, Mode=TwoWay}"
|
||||
Content="Запуск асистента"
|
||||
HorizontalAlignment="Center"
|
||||
|
||||
@@ -11,7 +11,23 @@
|
||||
<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/>
|
||||
<vm:SettingsViewModel/>
|
||||
</Design.DataContext>
|
||||
<ListBox ItemsSource="{Binding Modules}"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch">
|
||||
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate x:DataType="vm:ModuleItem">
|
||||
<Border Background="DarkBlue" CornerRadius="5" Padding="10" Margin="5">
|
||||
<Grid ColumnDefinitions="*,Auto">
|
||||
<TextBlock Text="{Binding Name}" />
|
||||
<Button Content="Settings"
|
||||
Grid.Column="1"
|
||||
Command="{Binding SettingsCommand}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</Window>
|
||||
|
||||
Reference in New Issue
Block a user