Files
NebulaLauncher/Nebula.Launcher/Controls/FilterBox.cs
Cinka f066bb1188 - tweak: rework FileApi for services
- tweak: rework filter think
- add: content view button
- fix: little fixes in services
2025-05-02 20:06:33 +03:00

72 lines
1.7 KiB
C#

using System;
using System.Windows.Input;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Layout;
namespace Nebula.Launcher.Controls;
public class FilterBox : UserControl
{
public static readonly StyledProperty<ICommand> FilterCommandProperty =
AvaloniaProperty.Register<FilterBox, ICommand>(nameof(FilterCommand));
public ICommand FilterCommand
{
get => GetValue(FilterCommandProperty);
set => SetValue(FilterCommandProperty, value);
}
public Action<FilterBoxChangedEventArgs>? OnFilterChanged {get; set;}
public string? FilterBoxName {
set => filterName.Text = value;
get => filterName.Text;
}
private StackPanel filterPanel;
private TextBox filterName = new TextBox();
public FilterBox()
{
filterPanel = new StackPanel()
{
Orientation = Orientation.Horizontal,
Spacing = 5,
};
Content = filterPanel;
}
public void AddFilter(string name, string tag)
{
var checkBox = new CheckBox();
checkBox.Content = new TextBlock()
{
Text = name,
};
checkBox.IsCheckedChanged += (_, _) =>
{
var args = new FilterBoxChangedEventArgs(tag, checkBox.IsChecked ?? false);
OnFilterChanged?.Invoke(args);
FilterCommand?.Execute(args);
};
filterPanel.Children.Add(checkBox);
}
}
public sealed class FilterBoxChangedEventArgs : EventArgs
{
public FilterBoxChangedEventArgs(string name, bool @checked)
{
Tag = name;
Checked = @checked;
}
public string Tag {get; private set;}
public bool Checked {get; private set;}
}