using Avalonia.Controls;
using Avalonia.Media;
using NewLife.Studio.Core;
namespace NewLife.Studio.App.Controls;
public partial class NavBar : UserControl
{
public event EventHandler<ModuleInfo>? ModuleSelected;
public NavBar()
{
InitializeComponent();
}
public void SetModules(IReadOnlyList<ModuleInfo> modules, ModuleInfo? activeModule)
{
ModuleList.Children.Clear();
foreach (var m in modules)
{
var isActive = m == activeModule;
var button = new Button
{
Width = 44,
Height = 44,
Padding = new Avalonia.Thickness(2),
Background = isActive
? new SolidColorBrush(Color.Parse("#007ACC"))
: Brushes.Transparent,
Content = new StackPanel
{
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center,
Children =
{
new TextBlock
{
Text = m.DisplayName,
FontSize = 10,
TextAlignment = TextAlignment.Center,
TextWrapping = TextWrapping.Wrap,
Width = 40,
Foreground = isActive ? Brushes.White : Brushes.Black
}
}
},
Tag = m
};
var capturedModule = m;
button.Click += (_, _) =>
{
ModuleSelected?.Invoke(this, capturedModule);
};
ModuleList.Children.Add(button);
}
}
}
|